From 4bfb82adf7feb8b9f646aa43d729fcf8915c56df Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Sun, 4 Dec 2011 15:47:16 -0500 Subject: [PATCH] compositor: Move a few more utils to util.c --- compositor/compositor.c | 119 ----------------------------------------------- compositor/compositor.h | 10 ++-- compositor/util.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+), 123 deletions(-) diff --git a/compositor/compositor.c b/compositor/compositor.c index 5bed7ba..2c04c3b 100644 --- a/compositor/compositor.c +++ b/compositor/compositor.c @@ -83,125 +83,6 @@ wlsc_watch_process(struct wlsc_process *process) wl_list_insert(&child_process_list, &process->link); } -WL_EXPORT void -wlsc_matrix_init(struct wlsc_matrix *matrix) -{ - static const struct wlsc_matrix identity = { - { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } - }; - - memcpy(matrix, &identity, sizeof identity); -} - -static void -wlsc_matrix_multiply(struct wlsc_matrix *m, const struct wlsc_matrix *n) -{ - struct wlsc_matrix tmp; - const GLfloat *row, *column; - div_t d; - int i, j; - - for (i = 0; i < 16; i++) { - tmp.d[i] = 0; - d = div(i, 4); - row = m->d + d.quot * 4; - column = n->d + d.rem; - for (j = 0; j < 4; j++) - tmp.d[i] += row[j] * column[j * 4]; - } - memcpy(m, &tmp, sizeof tmp); -} - -WL_EXPORT void -wlsc_matrix_translate(struct wlsc_matrix *matrix, GLfloat x, GLfloat y, GLfloat z) -{ - struct wlsc_matrix translate = { - { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1 } - }; - - wlsc_matrix_multiply(matrix, &translate); -} - -WL_EXPORT void -wlsc_matrix_scale(struct wlsc_matrix *matrix, GLfloat x, GLfloat y, GLfloat z) -{ - struct wlsc_matrix scale = { - { x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1 } - }; - - wlsc_matrix_multiply(matrix, &scale); -} - -static void -wlsc_matrix_transform(struct wlsc_matrix *matrix, struct wlsc_vector *v) -{ - int i, j; - struct wlsc_vector t; - - for (i = 0; i < 4; i++) { - t.f[i] = 0; - for (j = 0; j < 4; j++) - t.f[i] += v->f[j] * matrix->d[i + j * 4]; - } - - *v = t; -} - -WL_EXPORT void -wlsc_spring_init(struct wlsc_spring *spring, - double k, double current, double target) -{ - spring->k = k; - spring->friction = 400.0; - spring->current = current; - spring->previous = current; - spring->target = target; -} - -WL_EXPORT void -wlsc_spring_update(struct wlsc_spring *spring, uint32_t msec) -{ - double force, v, current, step; - - step = 0.01; - while (4 < msec - spring->timestamp) { - current = spring->current; - v = current - spring->previous; - force = spring->k * (spring->target - current) / 10.0 + - (spring->previous - current) - v * spring->friction; - - spring->current = - current + (current - spring->previous) + - force * step * step; - spring->previous = current; - -#if 0 - if (spring->current >= 1.0) { -#ifdef TWEENER_BOUNCE - spring->current = 2.0 - spring->current; - spring->previous = 2.0 - spring->previous; -#else - spring->current = 1.0; - spring->previous = 1.0; -#endif - } - - if (spring->current <= 0.0) { - spring->current = 0.0; - spring->previous = 0.0; - } -#endif - spring->timestamp += 4; - } -} - -WL_EXPORT int -wlsc_spring_done(struct wlsc_spring *spring) -{ - return fabs(spring->previous - spring->target) < 0.0002 && - fabs(spring->current - spring->target) < 0.0002; -} - static void surface_handle_buffer_destroy(struct wl_listener *listener, struct wl_resource *resource, uint32_t time) diff --git a/compositor/compositor.h b/compositor/compositor.h index 2781409..1d55158 100644 --- a/compositor/compositor.h +++ b/compositor/compositor.h @@ -36,6 +36,10 @@ struct wlsc_matrix { GLfloat d[16]; }; +struct wlsc_vector { + GLfloat f[4]; +}; + void wlsc_matrix_init(struct wlsc_matrix *matrix); void @@ -43,6 +47,8 @@ wlsc_matrix_scale(struct wlsc_matrix *matrix, GLfloat x, GLfloat y, GLfloat z); void wlsc_matrix_translate(struct wlsc_matrix *matrix, GLfloat x, GLfloat y, GLfloat z); +void +wlsc_matrix_transform(struct wlsc_matrix *matrix, struct wlsc_vector *v); struct wlsc_transform { struct wlsc_matrix matrix; @@ -244,10 +250,6 @@ enum wlsc_output_flags { WL_OUTPUT_FLIPPED = 0x01 }; -struct wlsc_vector { - GLfloat f[4]; -}; - struct wlsc_surface { struct wl_surface surface; struct wlsc_compositor *compositor; diff --git a/compositor/util.c b/compositor/util.c index 74d183d..38559c7 100644 --- a/compositor/util.c +++ b/compositor/util.c @@ -21,10 +21,131 @@ */ #include +#include #include +#include #include "compositor.h" +WL_EXPORT void +wlsc_matrix_init(struct wlsc_matrix *matrix) +{ + static const struct wlsc_matrix identity = { + { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 } + }; + + memcpy(matrix, &identity, sizeof identity); +} + +static void +wlsc_matrix_multiply(struct wlsc_matrix *m, const struct wlsc_matrix *n) +{ + struct wlsc_matrix tmp; + const GLfloat *row, *column; + div_t d; + int i, j; + + for (i = 0; i < 16; i++) { + tmp.d[i] = 0; + d = div(i, 4); + row = m->d + d.quot * 4; + column = n->d + d.rem; + for (j = 0; j < 4; j++) + tmp.d[i] += row[j] * column[j * 4]; + } + memcpy(m, &tmp, sizeof tmp); +} + +WL_EXPORT void +wlsc_matrix_translate(struct wlsc_matrix *matrix, GLfloat x, GLfloat y, GLfloat z) +{ + struct wlsc_matrix translate = { + { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, x, y, z, 1 } + }; + + wlsc_matrix_multiply(matrix, &translate); +} + +WL_EXPORT void +wlsc_matrix_scale(struct wlsc_matrix *matrix, GLfloat x, GLfloat y, GLfloat z) +{ + struct wlsc_matrix scale = { + { x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1 } + }; + + wlsc_matrix_multiply(matrix, &scale); +} + +WL_EXPORT void +wlsc_matrix_transform(struct wlsc_matrix *matrix, struct wlsc_vector *v) +{ + int i, j; + struct wlsc_vector t; + + for (i = 0; i < 4; i++) { + t.f[i] = 0; + for (j = 0; j < 4; j++) + t.f[i] += v->f[j] * matrix->d[i + j * 4]; + } + + *v = t; +} + +WL_EXPORT void +wlsc_spring_init(struct wlsc_spring *spring, + double k, double current, double target) +{ + spring->k = k; + spring->friction = 400.0; + spring->current = current; + spring->previous = current; + spring->target = target; +} + +WL_EXPORT void +wlsc_spring_update(struct wlsc_spring *spring, uint32_t msec) +{ + double force, v, current, step; + + step = 0.01; + while (4 < msec - spring->timestamp) { + current = spring->current; + v = current - spring->previous; + force = spring->k * (spring->target - current) / 10.0 + + (spring->previous - current) - v * spring->friction; + + spring->current = + current + (current - spring->previous) + + force * step * step; + spring->previous = current; + +#if 0 + if (spring->current >= 1.0) { +#ifdef TWEENER_BOUNCE + spring->current = 2.0 - spring->current; + spring->previous = 2.0 - spring->previous; +#else + spring->current = 1.0; + spring->previous = 1.0; +#endif + } + + if (spring->current <= 0.0) { + spring->current = 0.0; + spring->previous = 0.0; + } +#endif + spring->timestamp += 4; + } +} + +WL_EXPORT int +wlsc_spring_done(struct wlsc_spring *spring) +{ + return fabs(spring->previous - spring->target) < 0.0002 && + fabs(spring->current - spring->target) < 0.0002; +} + struct wlsc_zoom { struct wlsc_surface *surface; struct wlsc_animation animation; -- 2.7.4