New display warping function: DisplayUndistortionCSV / NVidia Warp-API

The new function DisplayUndistortionCSV() allows import of a .csv ASCII
calibration file as used for NVidia's proprietary Warp-API into a .mat
format that Screen's warp engine can handle. This allows for
compatibility between both worlds.

The CSV format defines a quad-mesh as a set of vertices with texcoords,
just as our BVL calibration method, except that the final mesh is
explicitely stored in the file, instead of a set of calibration points
to which a mesh is fitted during runtime.

CreateDisplayWarp() updated to handle the new method.
PsychImaging: Compatibility fix for NVidia binary blob on Linux.

Some versions of the binary blob throw a benign OpenGL error
inside the Psychimaging geometry correction setup. Reason is unclear,
doesn't happen on other setups, seems to have no actual harmful effect
on behaviour. Probably a bug in the NVidia blob.

Workaround it by reporting the error and just going on. Otherwise
it can lead to an error abort for no good reason.
PsychTests/GraphicsDisplaySyncAcrossDualHeadsTestLinux: Small tweaks.

Just hacks to make it more efficient on Linux + NVidia binary blob.
Would be better to enable the disabled code herein if on DRI2/KMS
stack, where we can take advantage of the values processed by the
now disabled code.
Rebuild Screen for 64-Bit Matlab on OSX for testing.
Screen: Optimize Screen('Begin/EndOpenGL') for certain cases.

Avoid some redundant calls. Verify what can be optimized and what not.

Avoid OpenGL glGetError() checks if kPsychAvoidCPUGPUSync is set, also
in imaging pipeline.

Avoid redundant context/framebuffer switches and pipeline flushes if
sharecontext flag is set to 1, ie., 2D context shall be (ab)used for
3D userspace rendering.

Screen for 64-Bit Matlab on OSX rebuilt and tested.
Unclear if this really has much impact on real world performance.
Screen: Initialize glViewPort() et al. in Screen('BeginOpenGL').

Many OpenGL rendering scripts omit setting a proper glViewPort().
This works fine in non-stereo display modes, because gl spec says
the viewport and scissor rectangle get set to the full size of
a drawable at first bind of the OpenGL context after creation.

However this didn't happen if a stereo mode that alters the client
rendering area was active, or rendering into an offscreen window of
different size than its parent window. Well, it did happen, but
the viewport was set at onscreen window creation time, therefore
wrong for such use cases, leading to rather mysterious distortions
in rendering if usercode didn't explicitely set the viewport to
a suitable area.

Now, at first invocation of Screen('BeginOpenGL') ie., first real
use of the userspace rendering context, we set th viewport, scissor,
projection matrix to the real client area to replicate OpenGL
"init on first bind" semantics.

Technically we don't need to do this, this was not a bug, but so far
MK wasted over 1 day debugging mysterious problems caused by him
forgetting a required glViewPort call. Make the thing more idiot proof to
prevent idiots like him wasting lots of time.

Screen for 64-Bit Matlab OSX rebuilt and tested.
Screen for 64-Bit Octave on Linux rebuilt for testing.
Screen: Improve movie deletion for Quicktime and GStreamer engines.

We were always calling OpenGL functions in the delete movie routines
without setting the OpenGL context of the associated parent windowRecord
of a given movie. Iow, we were depending on luck if the right context
was bound at movie deletion time - which was probably the case 99% of
the time due to OpenGL resource sharing etc.

Now we keep track of the parent windowRecord of a movie and activate
its OpenGL context before doing OpenGL calls, so we no longer depend
on luck that much.

Note: This introduces another problem. We do not reference count our
windowRecords, so it could happen that we close a window while still
having some dependencies on it, e.g., due to open movie files, video
capture session, etc. This is a potential crasher!

However, the typical shutdown sequence of user scripts doesn't cause
this and no time now to fix it properly, which would mean introducing
reference counting for all windows everywhere. Not difficult, just
tedious.

So we are still powered by luck.
Screen: Enable movie texture recycling in GStreamer playback engine.

Turns out that texture recycling for movie textures was disabled
all the time in the GStreamer based movie playback engine due to
an omission of mine! Oh dear.

Now enabled, following the same strategy as on the old and now dead
Quicktime engine for Windows. Except we fixed some bug - we actually
detach all textures created from a movie from the movie when the
movie is closed, so no recycled texture can leak. The windows QT
engine would leak up to one texture per closed movie file, depending
on exact usage pattern. Anyway, this is prehistorical PTB 3.0.9
stuff, so no bugfix there.

Screen for 64 Bit Matlab on OSX rebuilt, test pending.
Screen for 64-Bit Octave on Linux rebuilt for testing.
Screen: Add fast frameskipping to 'fortimeindex' pts.

If forward playback on GStreamer + async buffering is active, we now
try to honor the 'fortimeindex' parameter of Screen('GetMovieImage'),
which so far was ignored while active playback was on.

We do this by comparing a fetched videobuffers pts against
fortimeindex. If pts < fortimeindex and forward playback is active and
additional buffers are already queued in the appsink, we immediately
return the current buffer to the sink and pull the next one - wash,
rinse, repeat. This is only available under limited circumstances and
allowed to get silently skipped to avoid bad deadlocks.
Screen: Let usercode select max number of movie playback threads.

Instead of passing the maximum number of video decoder threads to use
via PsychTweak() and an environment variable, usercode can optionally
provide it as new argument to Screen('Openmovie'). This allows to set
the value on a per-movie basis, instead of only globally on a
per-session basis. Fine grained control is good for complex
multi-threading scenarios, or if multiple movies need to decode in
parallel.

We also change the default to "don't care". No longer is
multi-threading enabled with auto-select setting zero, but the codecs
default of (probably) single-threading is used. This is a more safe
choice, allowing to handle problematic, badly encoded or pathological
video files to play back without lockup.
Screen: GStreamer - Add ability to dump filter graph to dot file.

Now honors the PsychTweak('GStreamerDumpFilterGraph') command to dump
the complete GStreamer pipeline to a .dot file which can be visualized
with GraphViz for debugging. It dumps the pipeline in movie playback,
movie creation and video capture/recording.
PlayMoviesDemo: Expose optional 'maxThreads' parameter.

This way, users can easily experiment with the
Screen('Openmovie',...maxThreads) parameter.
Screen for 64-Bit Octave on Linux rebuilt for testing.
Screen/OSX: Make handling of hybrid-graphics more robust.

We now enumerate all PsychtoolboxKernelDriver instances in a system,
keeping handles for all GPUs around. We try to attach our beampos
queries and other low-level stuff to the non-Intel-IGP, ie., to the
discrete card, as that is what one usually wants and what the os
chooses by default. In the past, we simply connected to the first
driver instance, assuming/hoping it would be the right one. On my
test system, this hope was justified, but i don't know if this
happens by chance or by design, so it is better for Screen() to
detect potential misassignments and fix them.

During beamposition queries, if we detect bogus values on a hybrid
system while attached to the non-Intel discrete GPU, we switch to
the other (Intel integrated usually) GPU, trying to fix a mis-
assignment this way. This to handle the special case of integrated
GPU instead of discrete GPU in use. This allows Screen to do the
right thing with both the discrete NVidia and the integrated Intel HD
on a 2010 MBP with automatic graphics switching.

We still can't handle multi-GPU systems (MacPro) with multiple active
GPUs, but at least we should be somewhat more robust on hybrid-graphics
MacBookPros now.

Screen for 64-Bit Matlab on OSX rebuilt and tested.
Screen/OSX: Try to make PsychOSGetVBLTimeAndCount() more robust on 10.7+

Another futile attempt to make pigs fly. This should make CVDisplayLink()
timestamping more robust, but doesn't - at least not with the Intel HD
card on 10.7.4. Still breaks randomly, due to the crappy Corevideo
implementation of Apple.

Idea was to detect if vbl timestamp is delayed by almost 1 refresh
cycle and if so, add 1 refresh duration and count, because this
likely means that the corevideo callback is delayed wrt. to the
calling thread of PsychOSGetVBLTimeAndCount().

We know the strategy works, as we use it in some of the Linux KMS
drivers, but the situation on OSX is simply too hopeless.

On Apple os'es there's just no winning in the long run :(
Screen: Add initial aravissrc support to GStreamer video capture engine.

aravissrc is a GStreamer plugin that allows to use the aravis vision
library for video capture. The library allows access to cameras
conforming to the GeniCam standard.

This is a proof-of-concept implementation, so far untested. The plugin
is rather basic at the moment and doesn't support device enumeration,
so we can use it by passing deviceIndex=-8 and either no name to use
the default camera, or a 'targetmoviefile' name with a specific camera
name.

No control of any capture parameters is implemented so far.

Screen for 64-Bit Matlab on OSX rebuilt.
Screen for 64-Bit Octave on Linux rebuilt for testing.
Screen: Make aravissrc video source plugin actually work.

This allows use of the aravissrc GeniCam video capture plugin with the
GStreamer videocapture engine. The plugin can't enumerate video
devices, so the name of a camera needs to be explicitely provided via
deviceIndex==-8 and targetmoviename == Namestring of the camera to
open. The plugin can't enumerate/validate video modes, but it does
provide an auto-selected default video mode, so we skip
auto-validation, just as with the Directshow plugin on Windows.

The plugin provides a few special capture control parametes which we
handle:

'Gain' = Integral value in decibel for electronic amplifier gain.
'Shutter' = Exposure time / Shutter time, but needs special treatment
as resolved in microseconds, instead of the usual nanoseconds.
Gain and Shutter have an Auto mode for auto-gain/shutter control.
'offset-x' and 'offset-y' to shift the (x,y) start of the cameras
hardware ROI.
'h-binning' and 'v-binning' CCD sensor pixel binning, whatever that is?

Screen for 64-Bit Matlab on OSX rebuilt and tested with the aravissrc
plugin for OSX and the simulated fake camera 'Fake_1', as i don't have
any access to real GeniCam cameras.

VideoCaptureDemo now accepts optional camera name string for video
sources.