Screen/Windows: Switch 32-Bit build from OSSBuilds Gstreamer to Gstreamer SDK.

Update build file to compile and link against 32-Bit GStreamer SDK
instead of 32-Bit OSSBuilds runtime. Enable GstEncodingProfiles for
video recording on 32-Bit Windows in source code. Update PsychStartup.m
to setup path to 32-Bit SDK.

-> Screen for 32-Bit Matlab on Windows rebuilt.
Core: Do not use stdint.h on MS-Windows, but #define needed types ourselves.

If we want to build mex files for Windows-PTB against the Microsoft
common C runtime library (msvcrt.dll) instead of the Microsoft Visual
Studio 2010 C libraries, we can't #include <stdint.h> as this will
cause various compile errors.

Therefore don't include stdint.h but #define the two needed constants
INT64_MAX and INT32_MAX ourselves.

Tested and shown to compile correctly with all mex files on 64-Bit
Matlab on Windows.
Screen('DrawText')/Windows: Only use process-global text encoding locales.

Turns out the Microsoft common C runtime doesn't support
_create_locale() and _free_locale() for creation of locale setting
objects. To remove the need for these functions and unify more code
paths, get rid of these local locale settings.

We now only use setlocale() + caching of locale settings to change the
process-global locale setting during text conversion as part of
Screen('DrawText'), ie., store backup copy of global setting, change
global setting to our wanted setting, perform decoding with that
setting, restore original process locale. This temporary change of
locale should hopefully not have side effects.

-> Allow buildings with MSCRT.dll
windowsmakeit64: Switch build of Screen.mexw64 to use mscrt.dll.

Add the hodgepdoge of compiler and linker options to build against the
mscrt.lib/dll provided by the "Windows Driver Development Kit"
(WinDDK). With the WinDDK from Microsoft installed, this allows
building of Screen.mexw64 against mscrt.dll instead of the Microsoft
Visual Studio 2010 C runtime.

Small Plus: Consistent with GStreamer dll's.
Big Minus: Code review shows that the "plus" shouldn't matter given how
we use the GStreamer dll's. We already avoid all potential interactions
with GStreamer which could cause hazards. Building against mscrt.dll
makes it impossible for us to pass environment variables from Matlab to
Screen() or GStreamer, effectively disabling almost all PsychTweak()
functionality and reducing the effectiveness of workarounds for broken
computer clocks.

-> Hopefully this change won't be needed, it is a big net minus!

Here are the things that could cause trouble according to MSDN
documentation if we don't build against mscrt.dll: 1. Passing
environment variables (won't work - they don't show up across dll
boundaries), 2. Passing file handles (which we don't do), 3. Passing
locale settings (which we don't do), 4. malloc()'ing memory on our side
and provide it to GStreamer to own it (which we don't do), 5. free()ing
memory pointers provided by GStreamer (which we don't do). Point 1
explains why the GStreamer debug environment variable settings via
PsychTweak() never had an effect on Windows, but only on OSX and Linux.
Point 2 and 3 we don't do. Point 4 or 5 would cause heap corruption,
but we don't do this. So for all practical means and purposes we should
be just fine using the standard msvc2010 runtime libs as in the past.
Screen for 32/64-Bit Matlab on Windows rebuilt and tested.

32-Bit Screen() just incorporates the locale setting changes from
previous commit.
64-Bit Screen() is linked against mscrt.dll instead of the MS-VisualC
2010 dll's.
-> The latter one is important for testing.
Screen: Make g_thread_init() call conditional on GLib version.

g_thread_init() is only needed up to GLib version < 2.31.0, but
deprecated above. Add a version check macro to avoid compiling it on
GLib >=2.31.0.
Screen/Windows: Add special GStreamer debug code for msvcrt builds.

On Windows + msvcrt builds, no env variables can be passed from Matlab
to Screen+Gstreamer, therefore use a trick to define GST_DEBUG env
variable at Screen verbosity > 20 inside Screen to pass it to
GStreamer. Didn't work either on R2012a, probably because stderr gets
redirected to nirvana. Whatever...
Screen.mexw64 for 64-Bit Matlab on Windows rebuilt and tested.

Another minor candidate for crash testing. Previous builds didn't
improve situation on affected machine out there.
Merge pull request #38 from Psychtoolbox-3/master

Resync with current master of official Psychtoolbox-3 repo.
For PTB BETA "Stadtmusikanten"
Screen/GStreamer: Protect against OpenGL context change during gst_init_check().

Apitrace'ing on Windows shows that GStreamer SDK, during gst_init_check()
(== at first-time initialization) creates and binds its own OpenGL context
on our thread behind our back, probably during some plugin enumeration for
OpenGL related plugins like gst-clutter. It fails to restore our OpenGL
context binding, so our code erroneously executes gl calls on the GStreamer
context instead of our own context --> Funny results ensue.

Add some PsychSetGLContext(win) calls after GSCheckInit() in OpenVideocapture
and OpenMovie implementations of the GStreamer backend. This guarantees that
our own Screen mastercontext is bound at the time we issue gl calls to setup
video capture or video playback, e.g., while we create and assign our YUV-I420
video decoding shaders.

Apitrace'ing shows that this stops the mess, and related gl error conditions
disappear in the trace. I assume this would fix the problems mentioned in
forum msg #16486 at first movie playback with pixelformat=6 after Matlab
was started. However, Matthew needs to verify this, as my VirtualBox Windows VM
is too broken wrt. shader operations to check this myself.

-> Screen.mex32/64 for 32/64-Bit Matlab on Windows rebuilt and apitrace tested.
-> Both Screens built against GStreamer SDK 2013.6.
-> Screen.mexw64 built against the MSCRT.dll.
Screen: Don't make window transparent for mouse for shieldinglevel < 1000.

Only make windows transparent for mouse for windowShieldingLevels
between 1000 and 1499. This was so on OSX, but inconsistent on Linux
and Windows.

-> Screen.mexw64 for 64-Bit Matlab on Windows rebuilt and tested.
-> Other mex files will be rebuild later together with other changes.
Screen: Be more clever about 10 bpc framebuffers.

Check if a bpc=10 requested native framebuffer is set up 10 bpc via
query to OpenGL context. Only fallback to PsychtoolboxKernelDriver /
MMIO tricks, or eventually fail, if that is not the case.
This makes detection of need for MMIO fallback on Linux more clever.
This makes detection of need for PsychtoolboxKernelDriver fallback on
OSX more clever, as it at least tries to get 10 bpc from the OS, before
falling back to our own solution. Note that as of OSX 10.8, 10 bit
native framebuffers are still not supported, and likely this will also
be the case for the upcoming 10.9 Mavericks. This change in code is
just to make us behave intelligently if Apple ever decided to honor
requests by its customers.

Also fix handling of AGL conserveVRAM settings for OSX in 'OpenWindow'.
Screen/OSX: Drop support for AGL + Carbon, cleanup Cocoa path.

This removes all support for AGL + Carbon windows, and for OSX 10.5
Now we always use CGL for OpenGL, and for windowed mode or
half-transparent windows, we use CGL wrapped into NSOpenGL contexts +
windows created by Cocoa. This allowed for a nice cleanup of the
PsychCocoaGlue.c and PsychWindowGlue.c files.

-> Screen for 64-Bit Matlab and Octave on OSX rebuilt and tested.
Screen: Make GStreamer the default videocapture engine on all OSes.

So far the default was different on 32-Bit OSX, but this is now
unsupported.
Screen/OSX: Split vbl timestamping into separate shm and cvdisplaylink

Disentagle both mehods, so one can work without the other:
Only good old and reliable iofb shmem vbl irq timestamping on 10.6.
Only new and crappy CVDisplayLink timestamping on 10.7 and later.

Screen for OSX rebuilt.
Screen/OSX: Disable screen release/capture hack for cgl windows.

The hack was to release a captured display, then CGLClearDrawable to
detach the OpenGL context from the display, then capture the display
again. This was to fix some display corruption in stereo display mode
on OSX 10.5.x

As 10.5 is no longer supported, remove the workaround and just
CGLClearDrawable().
Fixes some warning messages in system log on 10.7.

-> Screen for OSX rebuilt and tested.
Screen/OSX: Fix window placement and position/size queries under Cocoa.

On multi-display setups, fullscreen windows on secondary displays were
misplaced if use of Cocoa was requested for fullscreen mode. -> Fixed.
Related, Screen('Rect') and Screen('GlobalRect') could return wrong
info on windows placed on secondary displays if the windows were
kPsychGUIWindows's. -> Fixed.
Screen/OSX: Allow OpenGL context sharing between fullscreen and windowed windows.

Both the Cocoa window setup code and the pure fullscreen setup code now
share the same underlying CGL contexts. For Cocoa, NSOpenGL contexts
are wrapped around the CGL contexts. The fact windowed vs. non-windowed
onscreen windows nor always operate with OpenGL contexts from CGL
allows OpenGL context resource sharing across fullscreen CGL and
windowed Cocoa windows.

All that was needed was to remove the pixelformat attribute
kCGLPFAFullScreen. This attribute is deprecated as of OSX 10.6, not
really needed anymore on 10.6+, and it was preventing context resource
sharing.

-> Testing on OSX 10.7.5 with NVidia GeForce 330M on dual-display
worked.
-> Screen's for OSX rebuilt.
Update lib HIDAPI for Linux with latest bug fixes:

Merge upstream's master as of 10th September 2013 in order to
get the setlocale() fix for Linux which caused a very ugly bug, as
reported by Ian Mackenzie in forum message #16555.

This bug changed the LC_ALL, and thereby LC_NUMERIC locale setting
of the running octave process to system default, from "C". That
in turn caused decimal points "." no longer to be recognized by
octave and thereby parsing failure for all decimal numbers in scripts
or at the command line: Throwing away everything after the decimal
point caused all numbers to be floor()'ed to integers!

HIDAPI fixed this problem: It only changes the LC_CTYPE locale instead
of LC_ALL, so the LC_NUMERIC which is critical to us won't be touched
anymore in any case. Additionally it only changes LC_CTYPE if the
application hasn't set it itself already, thereby avoiding to mess
with app settings.

-> Renamed hid-libusb.c to hid.c for consistency across platforms.
-> Will require a rebuilt of PsychHID for Linux.
PsychHID: Resync HIDAPI with current upstream master.

-> Mostly comment formatting fixes.
-> Minor improvements.
-> Some robustness fixes.
-> Needs recompile of PsychHID for Windows.