compositor: add support for OES_EGL_image_external

In cases where the GPU can natively handle certain YUV formats,
eglQueryWaylandBufferWL() can return the value EGL_TEXTURE_EXTERNAL_WL
and the compositor will treat the buffer as a single egl-image-external.

See:
http://www.khronos.org/registry/gles/extensions/OES/OES_EGL_image_external.txt

v1: original
v2: rename EGL_TEXTURE_EXTERNAL_OES -> EGL_TEXTURE_EXTERNAL_WL and query
    for the extension
v3: fix build without updated mesa headers, if EGL_TEXTURE_EXTERNAL_WL
    #define is missing from older mesa headers.
v4: resend without missing parts

Signed-off-by: Rob Clark <rob@ti.com>
compositor: simplify shaders

Re-work how the shaders and emitted vertices work.  Rather than always
rendering clip-rect sized quads and doing transformation in tex coords
(and requiring the corresponding clipping in frag shader), instead
emit transformed vertices, clipped wrt. dirty region, and use simpler
frag shaders.  Also, split the rendering, so blended surfaces with an
opaque region have the opaque region drawn with blend disabled.  The
result is considerably fewer pixels drawn with blend enabled, and much
fewer cycles in the frag shader.

This requires having some more complex logic to figure out the vertices
of the shape which forms the intersection of the clip rect and the
transformed surface.  Which has perhaps got a few bugs or missing cases,
still (visual glitches in some cases) but at this point more or less is
starting to work.  I think it is at least far enough along to get some
initial review.

The result, on small SoC GPU (omap4/pandaboard) on 1920x1080 display,
for simple stuff like moving windows around, I get 60fps (before 30fps
or less), and pushing YUV buffers for hw decoded 1080p video goes from
~6fps to 30fps, with no drop in framerate for transformed/rotated video
surface.

v1: original
v2: check that perpendicular intersect vertex falls within bounds of
    transformed surface
v3: update w/ comments and fixes from Pekka Paalanen
v4: fix for full surface alpha from Pekka Paalanen, fix compositor-
    wayland build

Signed-off-by: Rob Clark <rob@ti.com>
compositor: specialised fragment shader for RGBX

Remove the weston_surface::blend attribute, which really meant that the
texture produced valid alpha values. This was used to override the opaque
region for RGBX surfaces, which produce undefined values for alpha.

Instead, compile a new shader especially for RGBX surfaces, that
hardcodes the sampled alpha as 1.0.

Before "compositor: optimize/simplify shaders" there was a 'vec4 opaque'
in the shaders, that would cause part of the texture to be forced to
alpha=1.0. Now that is gone, and we need this replacement.

To test: launch simple-shm, and use the super+alt+mousewheel combination
to make it transparent. It should not show a light cross over the window.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
compositor: fix blending for full-surface alpha

We can use and render the opaque region only, if we are not applying a
full-surface alpha.

Test case: weston-terminal; use super+alt+mousewheel to adjust the
window transparency. Before it went black, now it blends correctly.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
compositor: triangle fan debug

Draw the borders of all the triangles.

v1: original
v2: add keybinding to enable/disable fan debug (super-alt-space),
    cycle colors to make it easier to see individual draws, and
    redraw undamaged region to clean up previous frames debug
    lines

Signed-off-by: Rob Clark <rob@ti.com>
simple-egl: Remove unused variable.
simple-egl: Only set alpha_size=0 when -o is passed.

When starting simple-egl with -f for fullscreen and toggling to 'windowed' mode with F11,
the surface is opaque instead of semi-trnasparent as it is when starting without -f. We
only want to create the surface with alpha_size=0 when the user explicitly passes -o
because otherwise it will never have the ability to use alpha.
simple-egl: Avoid race condition.

After explaining the problem on irc, Pekka dictated this solution which works.
The problem is that simple-egl can hang when toggling fullscreen because of a
race where (quoting Pekka) "if it dispatches the frame callback simple-egl
itself requested before the Mesa's own frame callback came, simple-egl will go
to its redraw routing and call eglSwapBuffers so you end up effectively calling
eglSwapBuffers from within eglSwapBuffers, and deadlock". This patch avoids
redrawing (which calls eglSwapBuffers) when there is a pending frame callback.
Add sample configuration for workspaces to weston.ini

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
shell: Always set focus when restoring focus state

To avoid having a surface on a hidden workspace in focus always set the
focus (even to NULL) when restoring.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
shell: Add possibility to move surfaces to other workspaces

By default, Control + Shift + Up/Down will move the currently active
surface, if any, while changing to another workspace.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
shell: Introduce workspace manager interface

The workspace manager interface purpose is to provide clients with
control and knowledge about the current workspace state. Initially only
one function and one event exists; moving a surface and state updated
event. A workspace is represented as an index in a 1 dimensional array.

A client keeps track of the state by being broadcasted events when the
state changes, currently limited to current workspace or number of
workspaces available.

A client can send an asynchronous request to the manager asking to move
a surface to workspace identified by an index. It is up to the shell to
actually move it.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
toytoolkit: Implement support for the workspace manager interface

Two buttons are added to the right-click menu of the window frame for
moving a surface either up or down.

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
shell: Improve focus handling when moving surfaces between workspaces

Signed-off-by: Jonas Ådahl <jadahl@gmail.com>
workspaces: don't segfault on invalid move_surface_to_workspace request

Also fixes the off-by-one in toytoolkit that exposed the issue.
toytoolkit: supply correct widget in motion_handler callback
xwayland: replace opaque_rect, fix an alpha problem

Remove weston_surface::opaque_rect completely.

Instead, set the opaque region in xwayland.

Before this patch, black text in xterm was transparent. Now it is not.

However, this patch fixes only a part of the alpha problem. If you apply
full-surface alpha with super+alt+wheel, the problem reappears. This
problem is still due to bad alpha channel contents on xwayland windows.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
compositor: paint opaque regions with RGBX shader

weston_surface_draw() is restructured so that it will always use the
RGBX shader for opaque regions, if the surface is assigned the RGBA
shader.

Previously for opaque regions, we simply assumed, that the texture alpha
would be 1.0. If it was not (which really is an application bug), the
region would be misrendered. The RGBX shader forces the texture alpha to
1.0.

Xwayland surfaces may have bad alpha data in the opaque client area. If
blending was enabled, the bad alpha would be used with the RGBA shader.
This patch fixes rendering opaque xwayland windows with full-surface
alpha applied.

Test case: xterm, with full-surface alpha one step below 1.0. Before,
black text was fully transparent, now it is correctly only slightly
transparent.

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
compositor: fix fan_debug mode

- make it respect output transforms by making sure the uniforms are
  up-to-date

- properly restore the current shader program, in case it was
  overridden

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
compositor: reduce the number of triangles

The intersection of two rectangles is guaranteed to be convex. Therefore
we do not need a center vertex for the triangle fan, we can simply use
the whatever first vertex the intersection polygon has. This reduces the
number of triangles, while still painting the exact same area.

While at it, emit_vertex() nested function is factored into the
for-loop, since that is the only calling site left.

Comments are updated to reflect the changes, and some unrelated comment
fixes are in repaint_region().

Signed-off-by: Pekka Paalanen <ppaalanen@gmail.com>
Cc: Rob Clark <rob.clark@linaro.org>