Hi Pekka,<br><br>I notice you use the name 'ptr' which doesn't exactly fit the surrounding code. I don't really care for this, but I guess as long as it's used in context and has comments, it's ok.<br>


<br><div class="gmail_quote">On Tue, Dec 18, 2012 at 4:58 AM, Pekka Paalanen <span dir="ltr"><<a href="mailto:ppaalanen@gmail.com" target="_blank">ppaalanen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


Define struct weston_matrix_pointer, which acts as pointer to a matrix,<br>
not a matrix itself. This type is stored into<br>
weston_surface::geometry.transformation_list instead of<br>
weston_transform.<br>
<br>
This is a step towards making surface transformations properly<br>
inheritable. Transformation list can refer to another matrix, without<br>
adding hooks to maintain a copy of that matrix.<br>
<br>
Signed-off-by: Pekka Paalanen <<a href="mailto:ppaalanen@gmail.com" target="_blank">ppaalanen@gmail.com</a>><br>
---<br>
 src/compositor.c |   18 +++++++++++-------<br>
 src/compositor.h |   27 +++++++++++++++++++--------<br>
 src/shell.c      |   49 +++++++++++++++++++++++++++----------------------<br>
 src/util.c       |    5 +++--<br>
 4 files changed, 60 insertions(+), 39 deletions(-)<br>
<br>
diff --git a/src/compositor.c b/src/compositor.c<br>
index 24ae6e3..1533cbc 100644<br>
--- a/src/compositor.c<br>
+++ b/src/compositor.c<br>
@@ -293,9 +293,12 @@ weston_surface_create(struct weston_compositor *compositor)<br>
        wl_list_init(&surface->frame_callback_list);<br>
<br>
        wl_list_init(&surface->geometry.transformation_list);<br>
-       wl_list_insert(&surface->geometry.transformation_list,<br>
-                      &surface->transform.position.link);<br>
+<br>
        weston_matrix_init(&surface->transform.position.matrix);<br>
+       weston_transform_init(&surface->transform.position);<br>
+       wl_list_insert(&surface->geometry.transformation_list,<br>
+                      &surface->transform.position.ptr.link);<br>
+<br>
        pixman_region32_init(&surface->transform.boundingbox);<br>
        surface->transform.dirty = 1;<br>
<br>
@@ -539,7 +542,7 @@ weston_surface_update_transform_enable(struct weston_surface *surface)<br>
 {<br>
        struct weston_matrix *matrix = &surface->transform.matrix;<br>
        struct weston_matrix *inverse = &surface->transform.inverse;<br>
-       struct weston_transform *tform;<br>
+       struct weston_matrix_pointer *ptr;<br>
<br>
        surface->transform.enabled = 1;<br>
<br>
@@ -548,8 +551,9 @@ weston_surface_update_transform_enable(struct weston_surface *surface)<br>
        surface->transform.position.matrix.d[13] = surface->geometry.y;<br>
<br>
        weston_matrix_init(matrix);<br>
-       wl_list_for_each(tform, &surface->geometry.transformation_list, link)<br>
-               weston_matrix_multiply(matrix, &tform->matrix);<br>
+       wl_list_for_each(ptr, &surface->geometry.transformation_list, link) {<br>
+               weston_matrix_multiply(matrix, ptr->matrix);<br>
+       }<br>
<br>
        if (weston_matrix_invert(inverse, matrix) < 0) {<br>
                /* Oops, bad total transformation, not invertible */<br>
@@ -581,9 +585,9 @@ weston_surface_update_transform(struct weston_surface *surface)<br>
<br>
        /* transform.position is always in transformation_list */<br>
        if (surface->geometry.transformation_list.next ==<br>
-           &surface->transform.position.link &&<br>
+           &surface->transform.position.ptr.link &&<br>
            surface->geometry.transformation_list.prev ==<br>
-           &surface->transform.position.link) {<br>
+           &surface->transform.position.ptr.link) {<br>
                weston_surface_update_transform_disable(surface);<br>
        } else {<br>
                if (weston_surface_update_transform_enable(surface) < 0)<br>
diff --git a/src/compositor.h b/src/compositor.h<br>
index 3a3580a..b681481 100644<br>
--- a/src/compositor.h<br>
+++ b/src/compositor.h<br>
@@ -37,11 +37,6 @@<br>
        const __typeof__( ((type *)0)->member ) *__mptr = (ptr);        \<br>
        (type *)( (char *)__mptr - offsetof(type,member) );})<br>
<br>
-struct weston_transform {<br>
-       struct weston_matrix matrix;<br>
-       struct wl_list link;<br>
-};<br>
-<br>
 struct weston_surface;<br>
 struct shell_surface;<br>
 struct weston_seat;<br>
@@ -345,6 +340,16 @@ struct weston_compositor {<br>
        struct weston_xkb_info xkb_info;<br>
 };<br>
<br>
+struct weston_matrix_pointer {<br>
+       struct weston_matrix *matrix;<br>
+       struct wl_list link;<br>
+};<br>
+<br>
+struct weston_transform {<br>
+       struct weston_matrix matrix;<br>
+       struct weston_matrix_pointer ptr;<br>
+};<br>
+<br>
 struct weston_buffer_reference {<br>
        struct wl_buffer *buffer;<br>
        struct wl_listener destroy_listener;<br>
@@ -357,8 +362,8 @@ struct weston_region {<br>
<br>
 /* Using weston_surface transformations<br>
  *<br>
- * To add a transformation to a surface, create a struct weston_transform, and<br>
- * add it to the list surface->geometry.transformation_list. Whenever you<br>
+ * To add a transformation to a surface, create a struct weston_matrix_pointer,<br>
+ * and add it to the list surface->geometry.transformation_list. Whenever you<br>
  * change the list, anything under surface->geometry, or anything in the<br>
  * weston_transforms linked into the list, you must call<br>
  * weston_surface_geometry_dirty().<br>
@@ -402,7 +407,7 @@ struct weston_surface {<br>
                float x, y; /* surface translation on display */<br>
                int32_t width, height;<br>
<br>
-               /* struct weston_transform */<br>
+               /* struct weston_matrix_pointer::link */<br>
                struct wl_list transformation_list;<br>
        } geometry;<br>
<br>
@@ -845,4 +850,10 @@ weston_transformed_rect(int width, int height,<br>
                        enum wl_output_transform transform,<br>
                        pixman_box32_t rect);<br>
<br>
+static inline void<br>
+weston_transform_init(struct weston_transform *tform)<br>
+{<br>
+       tform->ptr.matrix = &tform->matrix;<br>
+}<br>
+<br>
 #endif<br>
diff --git a/src/shell.c b/src/shell.c<br>
index 5b9acd7..e25140d 100644<br>
--- a/src/shell.c<br>
+++ b/src/shell.c<br>
@@ -587,9 +587,9 @@ surface_translate(struct weston_surface *surface, double d)<br>
        struct weston_transform *transform;<br>
<br>
        transform = &shsurf->workspace_transform;<br>
-       if (wl_list_empty(&transform->link))<br>
+       if (wl_list_empty(&transform->ptr.link))<br>
                wl_list_insert(surface->geometry.transformation_list.prev,<br>
-                              &shsurf->workspace_transform.link);<br>
+                              &shsurf->workspace_transform.ptr.link);<br>
<br>
        weston_matrix_init(&shsurf->workspace_transform.matrix);<br>
        weston_matrix_translate(&shsurf->workspace_transform.matrix,<br>
@@ -666,9 +666,9 @@ workspace_deactivate_transforms(struct workspace *ws)<br>
<br>
        wl_list_for_each(surface, &ws->layer.surface_list, layer_link) {<br>
                shsurf = get_shell_surface(surface);<br>
-               if (!wl_list_empty(&shsurf->workspace_transform.link)) {<br>
-                       wl_list_remove(&shsurf->workspace_transform.link);<br>
-                       wl_list_init(&shsurf->workspace_transform.link);<br>
+               if (!wl_list_empty(&shsurf->workspace_transform.ptr.link)) {<br>
+                       wl_list_remove(&shsurf->workspace_transform.ptr.link);<br>
+                       wl_list_init(&shsurf->workspace_transform.ptr.link);<br>
                }<br>
                weston_surface_geometry_dirty(surface);<br>
        }<br>
@@ -919,9 +919,9 @@ take_surface_to_workspace_by_seat(struct desktop_shell *shell,<br>
                update_workspace(shell, index, from, to);<br>
        else {<br>
                shsurf = get_shell_surface(surface);<br>
-               if (wl_list_empty(&shsurf->workspace_transform.link))<br>
+               if (wl_list_empty(&shsurf->workspace_transform.ptr.link))<br>
                        wl_list_insert(&shell->workspaces.anim_sticky_list,<br>
-                                      &shsurf->workspace_transform.link);<br>
+                                      &shsurf->workspace_transform.ptr.link);<br>
<br>
                animate_workspace_change(shell, index, from, to);<br>
        }<br>
@@ -1434,8 +1434,8 @@ shell_unset_fullscreen(struct shell_surface *shsurf)<br>
        }<br>
        shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;<br>
        shsurf->fullscreen.framerate = 0;<br>
-       wl_list_remove(&shsurf->fullscreen.transform.link);<br>
-       wl_list_init(&shsurf->fullscreen.transform.link);<br>
+       wl_list_remove(&shsurf->fullscreen.transform.ptr.link);<br>
+       wl_list_init(&shsurf->fullscreen.transform.ptr.link);<br>
        if (shsurf->fullscreen.black_surface)<br>
                weston_surface_destroy(shsurf->fullscreen.black_surface);<br>
        shsurf->fullscreen.black_surface = NULL;<br>
@@ -1444,7 +1444,7 @@ shell_unset_fullscreen(struct shell_surface *shsurf)<br>
                                    shsurf->saved_x, shsurf->saved_y);<br>
        if (shsurf->saved_rotation_valid) {<br>
                wl_list_insert(&shsurf->surface->geometry.transformation_list,<br>
-                              &shsurf->rotation.transform.link);<br>
+                              &shsurf->rotation.transform.ptr.link);<br>
                shsurf->saved_rotation_valid = false;<br>
        }<br>
<br>
@@ -1508,9 +1508,9 @@ set_surface_type(struct shell_surface *shsurf)<br>
                shsurf->saved_y = surface->geometry.y;<br>
                shsurf->saved_position_valid = true;<br>
<br>
-               if (!wl_list_empty(&shsurf->rotation.transform.link)) {<br>
-                       wl_list_remove(&shsurf->rotation.transform.link);<br>
-                       wl_list_init(&shsurf->rotation.transform.link);<br>
+               if (!wl_list_empty(&shsurf->rotation.transform.ptr.link)) {<br>
+                       wl_list_remove(&shsurf->rotation.transform.ptr.link);<br>
+                       wl_list_init(&shsurf->rotation.transform.ptr.link);<br>
                        weston_surface_geometry_dirty(shsurf->surface);<br>
                        shsurf->saved_rotation_valid = true;<br>
                }<br>
@@ -1686,9 +1686,9 @@ shell_configure_fullscreen(struct shell_surface *shsurf)<br>
                                (float) surface->geometry.height;<br>
<br>
                weston_matrix_scale(matrix, scale, scale, 1);<br>
-               wl_list_remove(&shsurf->fullscreen.transform.link);<br>
+               wl_list_remove(&shsurf->fullscreen.transform.ptr.link);<br>
                wl_list_insert(&surface->geometry.transformation_list,<br>
-                              &shsurf->fullscreen.transform.link);<br>
+                              &shsurf->fullscreen.transform.ptr.link);<br>
                x = output->x + (output->width - surface->geometry.width * scale) / 2;<br>
                y = output->y + (output->height - surface->geometry.height * scale) / 2;<br>
                weston_surface_set_position(surface, x, y);<br>
@@ -1881,7 +1881,7 @@ shell_map_popup(struct shell_surface *shsurf)<br>
                        parent->geometry.y;<br>
        }<br>
        wl_list_insert(es->geometry.transformation_list.prev,<br>
-                      &shsurf->popup.parent_transform.link);<br>
+                      &shsurf->popup.parent_transform.ptr.link);<br>
<br>
        shsurf->popup.initial_up = 0;<br>
        weston_surface_set_position(es, shsurf->popup.x, shsurf->popup.y);<br>
@@ -2018,7 +2018,7 @@ create_shell_surface(void *shell, struct weston_surface *surface,<br>
        shsurf->fullscreen.framerate = 0;<br>
        shsurf->fullscreen.black_surface = NULL;<br>
        shsurf->ping_timer = NULL;<br>
-       wl_list_init(&shsurf->fullscreen.transform.link);<br>
+       wl_list_init(&shsurf->fullscreen.transform.ptr.link);<br>
<br>
        wl_signal_init(&shsurf->resource.destroy_signal);<br>
        shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy;<br>
@@ -2029,10 +2029,15 @@ create_shell_surface(void *shell, struct weston_surface *surface,<br>
        wl_list_init(&shsurf->link);<br>
<br>
        /* empty when not in use */<br>
-       wl_list_init(&shsurf->rotation.transform.link);<br>
+       wl_list_init(&shsurf->rotation.transform.ptr.link);<br>
+       weston_transform_init(&shsurf->rotation.transform);<br>
        weston_matrix_init(&shsurf->rotation.rotation);<br>
<br>
-       wl_list_init(&shsurf->workspace_transform.link);<br>
+       weston_transform_init(&shsurf->popup.parent_transform);<br>
+       weston_transform_init(&shsurf->fullscreen.transform);<br>
+<br>
+       wl_list_init(&shsurf->workspace_transform.ptr.link);<br>
+       weston_transform_init(&shsurf->workspace_transform);<br>
<br>
        shsurf->type = SHELL_SURFACE_NONE;<br>
        shsurf->next_type = SHELL_SURFACE_NONE;<br>
@@ -2497,7 +2502,7 @@ rotate_grab_motion(struct wl_pointer_grab *grab,<br>
        dy = wl_fixed_to_double(pointer->y) - rotate->center.y;<br>
        r = sqrtf(dx * dx + dy * dy);<br>
<br>
-       wl_list_remove(&shsurf->rotation.transform.link);<br>
+       wl_list_remove(&shsurf->rotation.transform.ptr.link);<br>
        weston_surface_geometry_dirty(shsurf->surface);<br>
<br>
        if (r > 20.0f) {<br>
@@ -2518,9 +2523,9 @@ rotate_grab_motion(struct wl_pointer_grab *grab,<br>
<br>
                wl_list_insert(<br>
                        &shsurf->surface->geometry.transformation_list,<br>
-                       &shsurf->rotation.transform.link);<br>
+                       &shsurf->rotation.transform.ptr.link);<br>
        } else {<br>
-               wl_list_init(&shsurf->rotation.transform.link);<br>
+               wl_list_init(&shsurf->rotation.transform.ptr.link);<br>
                weston_matrix_init(&shsurf->rotation.rotation);<br>
                weston_matrix_init(&rotate->rotation);<br>
        }<br>
diff --git a/src/util.c b/src/util.c<br>
index bae1bb9..91c83a6 100644<br>
--- a/src/util.c<br>
+++ b/src/util.c<br>
@@ -115,7 +115,7 @@ weston_surface_animation_destroy(struct weston_surface_animation *animation)<br>
 {<br>
        wl_list_remove(&animation->animation.link);<br>
        wl_list_remove(&animation->listener.link);<br>
-       wl_list_remove(&animation->transform.link);<br>
+       wl_list_remove(&animation->transform.ptr.link);<br>
        weston_surface_geometry_dirty(animation->surface);<br>
        if (animation->done)<br>
                animation->done(animation, animation->data);<br>
@@ -177,8 +177,9 @@ weston_surface_animation_run(struct weston_surface *surface,<br>
        animation->start = start;<br>
        animation->stop = stop;<br>
        weston_matrix_init(&animation->transform.matrix);<br>
+       weston_transform_init(&animation->transform);<br>
        wl_list_insert(&surface->geometry.transformation_list,<br>
-                      &animation->transform.link);<br>
+                      &animation->transform.ptr.link);<br>
        weston_spring_init(&animation->spring, 200.0, 0.0, 1.0);<br>
        animation->spring.friction = 700;<br>
        animation->animation.frame_counter = 0;<br>
<span><font color="#888888">--<br>
1.7.8.6<br>
<br>
_______________________________________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org" target="_blank">wayland-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</font></span></blockquote></div><br>