compositor: Move a few more utils to util.c

dev
Kristian Høgsberg 13 years ago
parent 2f88a40c57
commit 4bfb82adf7
  1. 119
      compositor/compositor.c
  2. 10
      compositor/compositor.h
  3. 121
      compositor/util.c

@ -83,125 +83,6 @@ wlsc_watch_process(struct wlsc_process *process)
wl_list_insert(&child_process_list, &process->link); 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 static void
surface_handle_buffer_destroy(struct wl_listener *listener, surface_handle_buffer_destroy(struct wl_listener *listener,
struct wl_resource *resource, uint32_t time) struct wl_resource *resource, uint32_t time)

@ -36,6 +36,10 @@ struct wlsc_matrix {
GLfloat d[16]; GLfloat d[16];
}; };
struct wlsc_vector {
GLfloat f[4];
};
void void
wlsc_matrix_init(struct wlsc_matrix *matrix); wlsc_matrix_init(struct wlsc_matrix *matrix);
void void
@ -43,6 +47,8 @@ wlsc_matrix_scale(struct wlsc_matrix *matrix, GLfloat x, GLfloat y, GLfloat z);
void void
wlsc_matrix_translate(struct wlsc_matrix *matrix, wlsc_matrix_translate(struct wlsc_matrix *matrix,
GLfloat x, GLfloat y, GLfloat z); GLfloat x, GLfloat y, GLfloat z);
void
wlsc_matrix_transform(struct wlsc_matrix *matrix, struct wlsc_vector *v);
struct wlsc_transform { struct wlsc_transform {
struct wlsc_matrix matrix; struct wlsc_matrix matrix;
@ -244,10 +250,6 @@ enum wlsc_output_flags {
WL_OUTPUT_FLIPPED = 0x01 WL_OUTPUT_FLIPPED = 0x01
}; };
struct wlsc_vector {
GLfloat f[4];
};
struct wlsc_surface { struct wlsc_surface {
struct wl_surface surface; struct wl_surface surface;
struct wlsc_compositor *compositor; struct wlsc_compositor *compositor;

@ -21,10 +21,131 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <stdio.h> #include <stdio.h>
#include <math.h>
#include "compositor.h" #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_zoom {
struct wlsc_surface *surface; struct wlsc_surface *surface;
struct wlsc_animation animation; struct wlsc_animation animation;

Loading…
Cancel
Save