Split the geometry information from weston_surface out into weston_view
The weston_surface structure is split into two structures:
* The weston_surface structure storres everything required for a
client-side or server-side surface. This includes buffers; callbacks;
backend private data; input, damage, and opaque regions; and a few other
bookkeeping bits.
* The weston_view structure represents an entity in the scenegraph and
storres all of the geometry information. This includes clip region,
alpha, position, and the transformation list as well as all of the
temporary information derived from the geometry state. Because a view,
and not a surface, is a scenegraph element, the view is what is placed
in layers and planes.
There are a few things worth noting about the surface/view split:
1. This is *not* a modification to the protocol. It is, instead, a
modification to Weston's internal scenegraph to allow a single surface
to exist in multiple places at a time. Clients are completely unaware
of how many views to a particular surface exist.
2. A view is considered a direct child of a surface and is destroyed when
the surface is destroyed. Because of this, the view.surface pointer is
always valid and non-null.
3. The compositor's surface_list is replaced with a view_list. Due to
subsurfaces, building the view list is a little more complicated than
it used to be and involves building a tree of views on the fly whenever
subsurfaces are used. However, this means that backends can remain
completely subsurface-agnostic.
4. Surfaces and views both keep track of which outputs they are on.
5. The weston_surface structure now has width and height fields. These
are populated when a new buffer is attached before surface.configure
is called. This is because there are many surface-based operations
that really require the width and height and digging through the views
didn't work well.
Signed-off-by: Jason Ekstrand <jason@jlekstrand.net>
diff --git a/src/gl-renderer.c b/src/gl-renderer.c
index f02445b..2cb24fa 100644
--- a/src/gl-renderer.c
+++ b/src/gl-renderer.c
@@ -193,7 +193,7 @@
* polygon area.
*/
static int
-calculate_edges(struct weston_surface *es, pixman_box32_t *rect,
+calculate_edges(struct weston_view *ev, pixman_box32_t *rect,
pixman_box32_t *surf_rect, GLfloat *ex, GLfloat *ey)
{
@@ -213,8 +213,8 @@
/* transform surface to screen space: */
for (i = 0; i < surf.n; i++)
- weston_surface_to_global_float(es, surf.x[i], surf.y[i],
- &surf.x[i], &surf.y[i]);
+ weston_view_to_global_float(ev, surf.x[i], surf.y[i],
+ &surf.x[i], &surf.y[i]);
/* find bounding box: */
min_x = max_x = surf.x[0];
@@ -238,9 +238,8 @@
* there will be only four edges. We just need to clip the surface
* vertices to the clip rect bounds:
*/
- if (!es->transform.enabled) {
+ if (!ev->transform.enabled)
return clip_simple(&ctx, &surf, ex, ey);
- }
/* Transformed case: use a general polygon clipping algorithm to
* clip the surface rectangle with each side of 'rect'.
@@ -257,11 +256,11 @@
}
static int
-texture_region(struct weston_surface *es, pixman_region32_t *region,
+texture_region(struct weston_view *ev, pixman_region32_t *region,
pixman_region32_t *surf_region)
{
- struct gl_surface_state *gs = get_surface_state(es);
- struct weston_compositor *ec = es->compositor;
+ struct gl_surface_state *gs = get_surface_state(ev->surface);
+ struct weston_compositor *ec = ev->surface->compositor;
struct gl_renderer *gr = get_renderer(ec);
GLfloat *v, inv_width, inv_height;
unsigned int *vtxcnt, nvtx = 0;
@@ -302,18 +301,20 @@
* form the intersection of the clip rect and the transformed
* surface.
*/
- n = calculate_edges(es, rect, surf_rect, ex, ey);
+ n = calculate_edges(ev, rect, surf_rect, ex, ey);
if (n < 3)
continue;
/* emit edge points: */
for (k = 0; k < n; k++) {
- weston_surface_from_global_float(es, ex[k], ey[k], &sx, &sy);
+ weston_view_from_global_float(ev, ex[k], ey[k],
+ &sx, &sy);
/* position: */
*(v++) = ex[k];
*(v++) = ey[k];
/* texcoord: */
- weston_surface_to_buffer_float(es, sx, sy,
+ weston_surface_to_buffer_float(ev->surface,
+ sx, sy,
&bx, &by);
*(v++) = bx * inv_width;
if (gs->y_inverted) {
@@ -331,9 +332,9 @@
}
static void
-triangle_fan_debug(struct weston_surface *surface, int first, int count)
+triangle_fan_debug(struct weston_view *view, int first, int count)
{
- struct weston_compositor *compositor = surface->compositor;
+ struct weston_compositor *compositor = view->surface->compositor;
struct gl_renderer *gr = get_renderer(compositor);
int i;
GLushort *buffer;
@@ -371,10 +372,10 @@
}
static void
-repaint_region(struct weston_surface *es, pixman_region32_t *region,
+repaint_region(struct weston_view *ev, pixman_region32_t *region,
pixman_region32_t *surf_region)
{
- struct weston_compositor *ec = es->compositor;
+ struct weston_compositor *ec = ev->surface->compositor;
struct gl_renderer *gr = get_renderer(ec);
GLfloat *v;
unsigned int *vtxcnt;
@@ -388,7 +389,7 @@
* polygon for each pair, and store it as a triangle fan if
* it has a non-zero area (at least 3 vertices1, actually).
*/
- nfans = texture_region(es, region, surf_region);
+ nfans = texture_region(ev, region, surf_region);
v = gr->vertices.data;
vtxcnt = gr->vtxcnt.data;
@@ -404,7 +405,7 @@
for (i = 0, first = 0; i < nfans; i++) {
glDrawArrays(GL_TRIANGLE_FAN, first, vtxcnt[i]);
if (gr->fan_debug)
- triangle_fan_debug(es, first, vtxcnt[i]);
+ triangle_fan_debug(ev, first, vtxcnt[i]);
first += vtxcnt[i];
}
@@ -464,28 +465,28 @@
static void
shader_uniforms(struct gl_shader *shader,
- struct weston_surface *surface,
- struct weston_output *output)
+ struct weston_view *view,
+ struct weston_output *output)
{
int i;
- struct gl_surface_state *gs = get_surface_state(surface);
+ struct gl_surface_state *gs = get_surface_state(view->surface);
glUniformMatrix4fv(shader->proj_uniform,
1, GL_FALSE, output->matrix.d);
glUniform4fv(shader->color_uniform, 1, gs->color);
- glUniform1f(shader->alpha_uniform, surface->alpha);
+ glUniform1f(shader->alpha_uniform, view->alpha);
for (i = 0; i < gs->num_textures; i++)
glUniform1i(shader->tex_uniforms[i], i);
}
static void
-draw_surface(struct weston_surface *es, struct weston_output *output,
- pixman_region32_t *damage) /* in global coordinates */
+draw_view(struct weston_view *ev, struct weston_output *output,
+ pixman_region32_t *damage) /* in global coordinates */
{
- struct weston_compositor *ec = es->compositor;
+ struct weston_compositor *ec = ev->surface->compositor;
struct gl_renderer *gr = get_renderer(ec);
- struct gl_surface_state *gs = get_surface_state(es);
+ struct gl_surface_state *gs = get_surface_state(ev->surface);
/* repaint bounding region in global coordinates: */
pixman_region32_t repaint;
/* non-opaque region in surface coordinates: */
@@ -495,8 +496,8 @@
pixman_region32_init(&repaint);
pixman_region32_intersect(&repaint,
- &es->transform.boundingbox, damage);
- pixman_region32_subtract(&repaint, &repaint, &es->clip);
+ &ev->transform.boundingbox, damage);
+ pixman_region32_subtract(&repaint, &repaint, &ev->clip);
if (!pixman_region32_not_empty(&repaint))
goto out;
@@ -505,13 +506,14 @@
if (gr->fan_debug) {
use_shader(gr, &gr->solid_shader);
- shader_uniforms(&gr->solid_shader, es, output);
+ shader_uniforms(&gr->solid_shader, ev, output);
}
use_shader(gr, gs->shader);
- shader_uniforms(gs->shader, es, output);
+ shader_uniforms(gs->shader, ev, output);
- if (es->transform.enabled || output->zoom.active || output->current_scale != es->buffer_scale)
+ if (ev->transform.enabled || output->zoom.active ||
+ output->current_scale != ev->surface->buffer_scale)
filter = GL_LINEAR;
else
filter = GL_NEAREST;
@@ -525,10 +527,11 @@
/* blended region is whole surface minus opaque region: */
pixman_region32_init_rect(&surface_blend, 0, 0,
- es->geometry.width, es->geometry.height);
- pixman_region32_subtract(&surface_blend, &surface_blend, &es->opaque);
+ ev->geometry.width, ev->geometry.height);
+ pixman_region32_subtract(&surface_blend, &surface_blend, &ev->surface->opaque);
- if (pixman_region32_not_empty(&es->opaque)) {
+ /* XXX: Should we be using ev->transform.opaque here? */
+ if (pixman_region32_not_empty(&ev->surface->opaque)) {
if (gs->shader == &gr->texture_shader_rgba) {
/* Special case for RGBA textures with possibly
* bad data in alpha channel: use the shader
@@ -536,21 +539,21 @@
* Xwayland surfaces need this.
*/
use_shader(gr, &gr->texture_shader_rgbx);
- shader_uniforms(&gr->texture_shader_rgbx, es, output);
+ shader_uniforms(&gr->texture_shader_rgbx, ev, output);
}
- if (es->alpha < 1.0)
+ if (ev->alpha < 1.0)
glEnable(GL_BLEND);
else
glDisable(GL_BLEND);
- repaint_region(es, &repaint, &es->opaque);
+ repaint_region(ev, &repaint, &ev->surface->opaque);
}
if (pixman_region32_not_empty(&surface_blend)) {
use_shader(gr, gs->shader);
glEnable(GL_BLEND);
- repaint_region(es, &repaint, &surface_blend);
+ repaint_region(ev, &repaint, &surface_blend);
}
pixman_region32_fini(&surface_blend);
@@ -560,14 +563,14 @@
}
static void
-repaint_surfaces(struct weston_output *output, pixman_region32_t *damage)
+repaint_views(struct weston_output *output, pixman_region32_t *damage)
{
struct weston_compositor *compositor = output->compositor;
- struct weston_surface *surface;
+ struct weston_view *view;
- wl_list_for_each_reverse(surface, &compositor->surface_list, link)
- if (surface->plane == &compositor->primary_plane)
- draw_surface(surface, output, damage);
+ wl_list_for_each_reverse(view, &compositor->view_list, link)
+ if (view->plane == &compositor->primary_plane)
+ draw_view(view, output, damage);
}
@@ -762,7 +765,7 @@
pixman_region32_subtract(&undamaged, &output->region,
output_damage);
gr->fan_debug = 0;
- repaint_surfaces(output, &undamaged);
+ repaint_views(output, &undamaged);
gr->fan_debug = 1;
pixman_region32_fini(&undamaged);
}
@@ -775,7 +778,7 @@
pixman_region32_union(&total_damage, &buffer_damage, output_damage);
- repaint_surfaces(output, &total_damage);
+ repaint_views(output, &total_damage);
pixman_region32_fini(&total_damage);
pixman_region32_fini(&buffer_damage);
@@ -830,6 +833,8 @@
struct gl_renderer *gr = get_renderer(surface->compositor);
struct gl_surface_state *gs = get_surface_state(surface);
struct weston_buffer *buffer = gs->buffer_ref.buffer;
+ struct weston_view *view;
+ int texture_used;
GLenum format;
int pixel_type;
@@ -850,7 +855,14 @@
* hold the reference to the buffer, in case the surface
* migrates back to the primary plane.
*/
- if (surface->plane != &surface->compositor->primary_plane)
+ texture_used = 0;
+ wl_list_for_each(view, &surface->views, surface_link) {
+ if (view->plane == &surface->compositor->primary_plane) {
+ texture_used = 1;
+ break;
+ }
+ }
+ if (!texture_used)
return;
if (!pixman_region32_not_empty(&gs->texture_damage))