winsys-glx: Reenable swap_region for llvmpipe and swrast

The bug that prevented MESA_copy_sub_buffer to work for swrast /
llvmpipe got fixed in mesa 10.1 git so enable it for mesa 10.1+.

https://bugzilla.gnome.org/show_bug.cgi?id=721450

When landing the patch, it was tweaked to #include "cogl-version.h" to
avoid a compiler warning about COGL_VERSION_ENCODE being implicitly
defined. -- Robert Bragg

Reviewed-by: Robert Bragg <robert@linux.intel.com>
winsys-glx: Fix swap region to remain disabled for old mesa

Commit a750f80c6aaa was supposed to enable it for newer mesa but was wrong,
fix that.
pipeline-cache: Prune old unused pipelines when the cache gets too big

Previously when a pipeline is added to the cache it would never be
removed. If the application is generating a lot of unique pipelines
this can end up effectively leaking a large number of resources
including the GL program objects. Arguably this isn't really a problem
because if the application is generating that many unique pipelines
then it is doing something wrong anyway. It also implies that it will
be recompiling shaders very often so the cache leaking will likely be
the least of the problems.

This patch makes it keep track of which pipelines in the cache are in
use. The cache now returns a struct representing the entry instead of
directly returning the pipeline. This entry contains a usage counter
which the pipeline backends can use to mark when there is a pipeline
alive that is using the cache entry. When the hash table decides that
it's a good time to prune some entries, it will make a list of all of
the pipelines that are not in use and then remove the least recently
used half of the pipelines. That way it is less likely to remove
pipelines that the application is actually regenerating often even if
they aren't in use all of the time.

When the cache is pruned the hash table makes a note of how small the
cache could be if it removed all of the unused pipelines. The hash
table starts pruning when there are more entries than twice this
minimum expected size. The idea is that if that case it hit then the
hash table is more than half full of useless pipelines so the
application is generating lots of redundant pipelines and it is a good
time to remove them.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
This re-licenses Cogl under the MIT license

This follows up on the proposal that was sent to the Cogl mailing list
to re-license from the LGPL to the MIT license:
http://lists.freedesktop.org/archives/cogl/2013-December/001465.html

Note: there was a copyright assignment policy in place for Clutter (and
therefore Cogl which was part of Clutter at the time) until the 11th of
June 2010 and so we only checked the details after that point (commit
0bbf50f905)

For each file, authors were identified via this Git command:
$ git blame -p -C -C -C20 -M -M10  0bbf50f905..HEAD

We received blanket approvals for re-licensing all Red Hat and Collabora
contributions which reduced how many people needed to be contacted
individually:
- http://lists.freedesktop.org/archives/cogl/2013-December/001470.html
- http://lists.freedesktop.org/archives/cogl/2014-January/001536.html

Individual approval requests were sent to all the other identified authors
who all confirmed the re-license on the Cogl mailinglist:
http://lists.freedesktop.org/archives/cogl/2014-January

As well as updating the copyright header in all sources files, the
COPYING file has been updated to reflect the license change and also
document the other licenses used in Cogl such as the SGI Free Software
License B, version 2.0 and the 3-clause BSD license.
Tweak documentation for the CoglTexture interface

The following changes are made to the documentation for CoglTexture:

• The description of the default value for the components property is
  changed to say that it is always RGBA for textures created by the
  ‘_with_size’ textures. Previously it said that the default is based
  on the pixel format used the first time data is set on the texture,
  but this is only true if the data is set using a constructor.

• Added documentation for the CoglTextureComponents enum.

• Changed it to say that it _specifies_ what components are required
  for sampling rather than determinging [sic] them.

• Added ‘Since: 1.18’ to
  cogl_texture_{set,get}_{components,premultiplied}

• Changed the since tag for CoglTextureError from 2.0 to 1.8.

• Added documentation for COGL_TEXTURE_ERROR_{FORMAT,TYPE}.

• Added the following to the cogl2-sections.txt file:
  COGL_TEXTURE_ERROR
  CoglTextureError
  cogl_texture_allocate
  cogl_texture_set_components
  cogl_texture_get_components
  cogl_texture_set_premultiplied
  cogl_texture_get_premultiplied

Reviewed-by: Robert Bragg <robert@linux.intel.com>
Add support for RG textures

This adds COGL_PIXEL_FORMAT_RG_88 and COGL_TEXTURE_COMPONENTS_RG in
order to support two-component textures. The RG components for a
texture is only supported if COGL_FEATURE_ID_TEXTURE_RG is advertised.
This is only available on GL 3, GL 2 with the GL_ARB_texture_rg
extension or GLES with the GL_EXT_texture_rg extension. The RG pixel
format is always supported for images because Cogl can easily do the
conversion if an application uses this format to upload to a texture
with a different format.

If an application tries to create an RG texture when the feature isn't
supported then it will raise an error when the texture is allocated.

https://bugzilla.gnome.org/show_bug.cgi?id=712830

Reviewed-by: Robert Bragg <robert@linux.intel.com>
Set the COGL_BITWISE_BIT flag for the formats with 10-bit components

The texture formats which have 10-bit components are necessarily not
byte-aligned so they ought to have the COGL_BITWISE_BIT flag. This
flag is enough to make them unique so they no longer need a new enum
value. The last enum value is therefore reset back to 1.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
winsys-wgl: Don't include cogl.h

Since 248a76f5eac7e5ae4fb45208577f9a55360812a7 cogl.h can no longer be
included in internal source files so the WGL winsys was no longer
compiling.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
mingw-fetch-dependencies: Add the -L option when using curl

The -L option makes curl follow redirections. This is needed for
downloading glext.h because khronos.org is using a redirect.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
cogl-gst: video-sink: fix not installed rgb shader

Reviewed-by: Neil Roberts <neil@linux.intel.com>
Update Chinese simplified translation
cogl-gst-video-sink: Premultiply the colors coming from the video

Commit 99a53c82e9ab0a1e5 removed the internal format argument when
uploading a video frame to a texture so that the format will just be
determined automatically from the image format. However this also
leaves the premultiplied state at the default and the default is TRUE.
That means that when we upload RGBA data Cogl will do a premultiplied
conversion on the CPU. We probably don't want to be putting a CPU
conversion in the way of video frames so this patch changes it to set
the premultiplied state to FALSE on the textures and then do the
premultiplied conversion in the shader.

This is particularly important for AYUV which uses the alpha channel
for the V component so doing a premultiplied conversion on the CPU
just creates garbage and messes up the image.

The RGB and RGBA renderers have each been split into two; one that
uses GLSL and one that uses a regular pipeline. The RGBA pipeline
without GLSL is then changed to use 2 layers so we that we can do the
premultiplied conversion in the second layer with a special layer
combine string.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
cogl-gst: video-sink: add NV12 support

This adds a cogl-gst renderer to decode NV12 data. NV12 is split into
two buffers, one for the luma component and another for the two
chrominance components at a quarter of the resolution. The second
buffer is uploaded to a two-component RG texture. RG-component
textures are only supported if COGL_FEATURE_ID_TEXTURE_RG is
advertised by Cogl so the NV12 cap is also only advertised when that
is available.

Based on a patch by Lionel Landwerlin which was in turn based on a
patch from Edward Hervey and Matthieu Bouron for Clutter-Gst:

https://bugzilla.gnome.org/show_bug.cgi?id=712832

Reviewed-by: Robert Bragg <robert@linux.intel.com>
Reviewed-by: Lionel Landwerlin <llandwerlin@gmail.com>
cogl-gst: Fix get_caps implementation when no context is set

If no context is set on the CoglGstVideoSink then it would previously
call gst_caps_ref with a NULL pointer. This patch makes it just return
NULL instead. I think that is a valid thing to do because that is what
gst_base_sink_default_get_caps does. If we don't do this then it's not
possible to use CoglGstVideoSink with GstParse because that tries to
link the pipeline after parsing the string. That was previously
causing a critical error because the freshly parsed sink doesn't have
a CoglContext.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
Reviewed-by: Lionel Landwerlin <llandwerlin@gmail.com>
cogl-basic-video-player: Allow passing a GStreamer pipeline

If the URI argument given on the command line doesn't look like a URI
then the basic video player will now try to parse it as a GStreamer
pipeline description. The pipeline must contain a coglsink element
which the player will look for. This can be used to test Cogl GST. For
example, to test NV12 this can be used:

./cogl-basic-video-player 'videotestsrc !
                           video/x-raw,format=(string)NV12 !
                           coglsink'

Reviewed-by: Robert Bragg <robert@linux.intel.com>
Updated FSF's address
Updated Ukrainian translation
Don't dereference an unitialised pointer in _cogl_container_of

The previous implementation was dereferencing the sample pointer in
order to get the offset to subtract from the member pointer. The
resulting value is then only used to get a pointer to the member in
order to calculate the offset so it doesn't actually read from the
memory location and shouldn't cause any problems. However this is
probably technically invalid and could have undefined behaviour. It
looks like clang takes advantage of this undefined behaviour and
doesn't actually offset the pointer. It also generates a warning when
it does this.

This patch splits the _cogl_container_of macro into two
implementations. Previously the macro was always used in the list
iterator macros like this:

SomeType *sample = _cogl_container_of(list_node, sample, link)

Instead of doing that there is now a new macro called
_cogl_list_set_iterator which explicitly assigns to the sample pointer
with an initial value before assigning to it again with the real
offset. This redundant initialisation gets optimised out by compiler.

The second macro is still called _cogl_container_of but instead of
taking a sample pointer it just directly takes the type name. That way
it can use the standard offsetof macro.

https://bugzilla.gnome.org/show_bug.cgi?id=723530

Reviewed-by: Robert Bragg <robert@linux.intel.com>
Allocate immediately in _cogl_egl_texture_2d_new_from_image

The _cogl_egl_texture_2d_new_from_image function has a CoglError
argument which implies that it is unlike the other texture
constructors and returns errors immediately rather than having a
delayed-allocation mechanism. cogl_wayland_texture_2d_new_from_buffer
which calls it is also like this. We can't rely on delayed-allocation
semantics for this without changing the applications because the
texture needs to be allocated before the corresponding EGLImage is
destroyed. This patch just makes it immediately allocate.

A better patch might be to remove the error argument to make it
obvious that there are delayed-allocation semantics and then fix all
of the applications.

This was breaking Cogland and Mutter.

Reviewed-by: Robert Bragg <robert@linux.intel.com>
kms: include stddef.h before drm.h

Not doing so leads to the following error, if stddef.h is not included
indirectly through EGL headers:

| libdrm/drm.h:132:2: error: unknown type name 'size_t'
|   size_t name_len;   /**< Length of name buffer */

Signed-off-by: Andreas Oberritter <obi@saftware.de>

Reviewed-by: Robert Bragg <robert@linux.intel.com>