NOT-FOR-UPSTREAM: gl/msaa: Use cached clip on non-texture surfaces

Instead of just relying on a cached clip for texture surfaces only, also
allow for caching the clip on the stencil buffer of non-texture
surfaces. This will not work if the stencil buffer is modified outside
cairo.
NOT-FOR-UPSTREAM: test: Use a percentage to check if pixels have changed.

Increase the PERCEPTUAL_DIFF_THRESHOLD and use a percentage of the
size of the image to check it the change is perceptible.
NOT-FOR-UPSTREAM: gl/msaa: Cache more GL states to avoid redundant operations

Cache the active texture, the RGBA values of glClearColor,
blend functions, blend state, and depth mask state.

FIXME: this commit adds restrictions about how applications can use
the GL context when using cairo.
NOT-FOR-UPSTREAM: This is an ugly hack that deals with mali driver bug.
NOT-FOR-UPSTREAM: gl: Cache glyph masks

This avoids the overhead of constantly binding new framebuffers, which
can be very slow on non-Intel hardware. See:
http://lists.cairographics.org/archives/cairo/2013-February/024073.html
CHERRY-PICK: gl: Set up operands when the vertex size changes

Previously _cairo_gl_composite_setup_vbo was overwriting the old context
vertex_size, while _cairo_gl_context_setup_operand was relying on it to
determine if the vertex size changed. Instead of a fragile ordering of
statements, pass whether the context changed as an argument to enforce
the calling order via method parameters.
CHERRY-PICK: gl: Fix typo in gles2 shader cache lookup

When comparing shader cache entries, it's important that we actually
compare the variable type hash.
CHERRY-PICK: gl/msaa: Resolve multisampling on surface flush

When flushing a surface, we must resolve multisampling for desktop GL.
This allows use of the original surface texture in any following raw GL
operations. This fixes accelerated canvas with WebKitGTK+ using the MSAA
compositor.
CHERRY-PICK: gl: Separate framebuffer bind from destination selection

Disentangle the action of binding the framebuffer from setting the
destination. This straightens up the code a bit and avoids some redundant
operations (such as reacquiring the context) when simply switching from
the multi-sample framebuffer to the single-sample framebuffer and vice
versa.
CHERRY-PICK: gl: Update transformation when surface size changes

In my previous commit I mistakenly removed the transformation matrix
update when cairo_gl_surface_set_size is called. This change restores
it.
CHERRY-PICK: gl: Bind the default framebuffer before calling gl{Read|Draw}Buffer

Fix more fallout from separating framebuffer binding from setting the
destination. In some cases it is sufficient to call
glDrawBuffer/glReadBuffer before binding the framebuffer, but the
masking-filling-stroking test of cairo-gl-smoke-tests fails if the order
is incorrect.
CHERRY-PICK: gles: Switch default framebuffer destinations properly

Make _cairo_gl_context_bind_framebuffer handle different types of GLES
surfaces properly Since, the multisampling setting of a surface never changes
in for GLES, so the first thing we do when setting the destination is to
ignore the requested multisampling setting. This simplifies all
following logic.