diff options
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | src/compositor.c | 49 | ||||
-rw-r--r-- | src/cwindow.c | 5 | ||||
-rw-r--r-- | src/lmctexture.c | 220 | ||||
-rw-r--r-- | src/lmctexture.h | 10 | ||||
-rw-r--r-- | src/lmctypes.h | 21 |
6 files changed, 205 insertions, 104 deletions
@@ -1,3 +1,7 @@ +Thu Apr 14 14:49:14 2005 Soeren Sandmann <sandmann@redhat.com> + + * Various updates to the GL compositor. Much less purple. + Wed Apr 13 14:58:18 2005 Søren Sandmann <sandmann@redhat.com> * lmctypes.h: Add this file diff --git a/src/compositor.c b/src/compositor.c index 67df2392..bdaead3a 100644 --- a/src/compositor.c +++ b/src/compositor.c @@ -294,6 +294,9 @@ meta_compositor_unref (MetaCompositor *compositor) #endif /* HAVE_COMPOSITE_EXTENSIONS */ } +double tmp; +static double last; +static GTimer *timer ; #ifdef HAVE_COMPOSITE_EXTENSIONS static void @@ -324,13 +327,19 @@ draw_windows (MetaCompositor *compositor, XFixesDestroyRegion (dpy, opaque); } - + draw_windows (compositor, screen, list->next, region_below, picture); XFixesDestroyRegion (dpy, region_below); if (cwindow_get_viewable (cwindow) && cwindow_get_xwindow (cwindow) != compositor->gl_window) + { cwindow_draw (cwindow, picture, damaged_region); +#if 0 + g_print ("drawing a window: %f\n", (tmp = g_timer_elapsed (timer, NULL)) - last); + last = tmp; +#endif + } } static Picture @@ -454,7 +463,7 @@ do_paint_screen (MetaCompositor *compositor, glDisable (GL_TEXTURE_2D); glDisable (GL_BLEND); - glViewport (0, 0, 1600, 1200); + glViewport (0, 0, screen->width, screen->height); #if 0 glClearColor (0.0, 0.5, 0.5, 0.0); @@ -503,10 +512,18 @@ do_paint_screen (MetaCompositor *compositor, glLoadIdentity(); - gluOrtho2D (0, 1600, 1200, 0); + gluOrtho2D (0, screen->width, screen->height, 0); glDisable (GL_SCISSOR_TEST); } + if (!timer) + timer = g_timer_new (); + +#if 0 + g_print ("outside: %f\n", (tmp = g_timer_elapsed (timer, NULL)) - last); + last = tmp; +#endif + draw_windows (compositor, screen, screen->compositor_windows, region, picture); if (USE_RENDER) { @@ -520,8 +537,25 @@ do_paint_screen (MetaCompositor *compositor, /* FIXME: we should probably grab the server around the raise/swap */ XRaiseWindow (compositor->display->xdisplay, compositor->gl_window); + +#if 0 + g_print ("painting window: %f\n", (tmp = g_timer_elapsed (timer, NULL)) - last); + last = tmp; +#endif + glXSwapBuffers (screen->display->xdisplay, compositor->gl_window); + + g_print ("in swap: %f\n", (tmp = g_timer_elapsed (timer, NULL)) - last); + last = tmp; + +#if 0 glFinish(); +#endif + +#if 0 + g_print ("inside: %f\n", (tmp = g_timer_elapsed (timer, NULL)) - last); + last = tmp; +#endif #if 0 XGCValues values; @@ -794,7 +828,9 @@ process_configure_notify (MetaCompositor *compositor, cwindow = g_hash_table_lookup (compositor->window_hash, &event->window); +#if 0 g_print ("configure: %lx above %lx\n", event->window, event->above); +#endif if (cwindow == NULL) { @@ -802,7 +838,9 @@ process_configure_notify (MetaCompositor *compositor, return; } +#if 0 g_print ("gl window: %lx\n", compositor->gl_window); +#endif handle_restacking (compositor, cwindow, g_hash_table_lookup (compositor->window_hash, &event->above)); @@ -1349,13 +1387,16 @@ meta_compositor_manage_screen (MetaCompositor *compositor, XVisualInfo *visual = init_gl (compositor->display->xdisplay, 0, &context); +#if 0 g_print ("dfepth: %d\n", visual->depth); g_print ("visual: %lx\n", visual->visualid); +#endif attr.colormap = XCreateColormap(compositor->display->xdisplay, screen->xroot, visual->visual, AllocNone); - w = XCreateWindow (compositor->display->xdisplay, screen->xroot, 0, 0, 1600, 1200, 0, + w = XCreateWindow (compositor->display->xdisplay, screen->xroot, 0, 0, + screen->width, screen->height, 0, visual->depth, InputOutput, visual->visual, CWColormap, &attr); diff --git a/src/cwindow.c b/src/cwindow.c index 48161909..195c0d92 100644 --- a/src/cwindow.c +++ b/src/cwindow.c @@ -1206,11 +1206,12 @@ cwindow_draw (CWindow *cwindow, if (rects) { gdk_region_offset (gdk_clip_region, -geometry->x, -geometry->y); - lmc_texture_draw (cwindow->texture, 1.0, geometry->x, geometry->y, gdk_clip_region); + lmc_texture_draw (cwindow_get_screen (cwindow), cwindow->texture, 1.0, geometry->x, geometry->y, gdk_clip_region); gdk_region_offset (gdk_clip_region, geometry->x, geometry->y); } else - lmc_texture_draw (cwindow->texture, 1.0, geometry->x, geometry->y, NULL); + lmc_texture_draw (cwindow_get_screen (cwindow), + cwindow->texture, 1.0, geometry->x, geometry->y, NULL); gdk_region_destroy (gdk_clip_region); } diff --git a/src/lmctexture.c b/src/lmctexture.c index cdc51669..40c75a10 100644 --- a/src/lmctexture.c +++ b/src/lmctexture.c @@ -1,6 +1,9 @@ +#include "config.h" #include "lmctexture.h" #include <string.h> #include <GL/glu.h> +#include "lmctypes.h" +#include "screen.h" typedef struct Tile Tile; @@ -10,6 +13,8 @@ struct Tile GLuint texture; }; +#define WOBBLE_TILE_SIZE 16 + struct _LmcTexture { /*< private >*/ @@ -18,25 +23,31 @@ struct _LmcTexture LmcBits *bits; GList *tiles; + + gint grid_width; + gint grid_height; + + LmcPoint *grid; }; static int get_max_texture_width (void) { - return 512; + return 128; return GL_MAX_TEXTURE_SIZE; } static int get_max_texture_height (void) { - return 512; + return 128; return GL_MAX_TEXTURE_SIZE; } static void dump_error (const char *context) { +#if 0 /* glGetError() is a server roundtrip */ GLenum err; @@ -46,6 +57,7 @@ dump_error (const char *context) const GLubyte *message = gluErrorString (err); g_warning ("GL Error: %s [at %s]\n", message, context); } +#endif } static int @@ -575,7 +587,7 @@ region_intersects_rect (GdkRegion *region, GdkRectangle *rect) static void print_gdk_region (const char *name, GdkRegion *region) { - GdkRectangle *rects; + GdkRectangle *rects; int i, n_rects; gdk_region_get_rectangles (region, &rects, &n_rects); @@ -586,6 +598,97 @@ print_gdk_region (const char *name, GdkRegion *region) g_free (rects); } +void +lmc_texture_set_deformation (LmcTexture *texture, + LmcDeformationFunc func, + void *data) +{ + int x, y, deformed_x, deformed_y; + LmcPoint *grid; + LmcBits *bits; + + if (func != NULL) + { + bits = texture->bits; + + texture->grid_width = + (bits->width + WOBBLE_TILE_SIZE - 1) / WOBBLE_TILE_SIZE + 1; + texture->grid_height = + (bits->height + WOBBLE_TILE_SIZE - 1) / WOBBLE_TILE_SIZE + 1; + grid = g_new0 (LmcPoint, texture->grid_width * texture->grid_height); + + for (y = 0; y < texture->grid_height; y++) + for (x = 0; x < texture->grid_width; x++) + { + func (x * WOBBLE_TILE_SIZE, y * WOBBLE_TILE_SIZE, + 0, 0, bits->width, bits->height, + &deformed_x, &deformed_y, + data); + grid[x + y * texture->grid_width].x = deformed_x; + grid[x + y * texture->grid_width].y = deformed_y; + } + } + else + grid = NULL; + + if (texture->grid) + g_free (texture->grid); + texture->grid = grid; +} + +static void +draw_tile (MetaScreen *screen, Tile *tile, int x, int y, GdkRegion *clip) +{ + if ((!clip || region_intersects_rect (clip, &tile->geometry))) + { + GdkRectangle *rects; + int n_rects; + int translated_x = tile->geometry.x + x; + int translated_y = tile->geometry.y + y; + int i; + GdkRectangle dummy; + + gdk_region_get_rectangles (clip, &rects, &n_rects); + + glEnable (GL_SCISSOR_TEST); + + glBindTexture (GL_TEXTURE_2D, tile->texture); + + for (i = 0; i < n_rects; ++i) + { + if (gdk_rectangle_intersect (&(rects[i]), &tile->geometry, &dummy)) + { + glScissor (rects[i].x + x, + screen->height - (y + rects[i].y + rects[i].height), + rects[i].width, + rects[i].height); + dump_error ("glbindtexture"); + + glBegin (GL_QUADS); + + /* corner 1 */ + glTexCoord2f (0.0, 0.0); + glVertex3i (translated_x, translated_y, 0); + + /* corner 2 */ + glTexCoord2f (1.0, 0.0); + glVertex3i (translated_x + tile->geometry.width, translated_y, 0); + + /* corner 3 */ + glTexCoord2f (1.0, 1.0); + glVertex3i (translated_x + tile->geometry.width, translated_y + tile->geometry.height, 0); + + /* corner 4 */ + glTexCoord2f (0.0, 1.0); + glVertex3i (translated_x, translated_y + tile->geometry.height, 0); + + glEnd (); + dump_error ("glEnd"); + } + } + } +} + /** * lmc_texture_draw: * @texture: @@ -597,7 +700,8 @@ print_gdk_region (const char *name, GdkRegion *region) * Draw the texture, the clip is in window coordinates. **/ void -lmc_texture_draw (LmcTexture *texture, +lmc_texture_draw (MetaScreen *screen, + LmcTexture *texture, double alpha, int x, int y, @@ -628,13 +732,15 @@ lmc_texture_draw (LmcTexture *texture, g_print ("alpha %f\n", alpha); #endif +#if 0 set_clip_region (clip, x, y); +#endif #if 0 glColor4f (g_random_double(), g_random_double(), - g_random_double(), 0.3); - + g_random_double(), 0.3); + glBegin (GL_QUADS); glVertex3i (0, 0, 0); @@ -647,100 +753,22 @@ lmc_texture_draw (LmcTexture *texture, goto out; #endif - glColor4f (1.0, 1.0, 1.0, alpha); +#if 0 + glColor4f (g_random_double(), + g_random_double(), + g_random_double(), 1); + +#endif + + glColor4f (1.0, 1.0, 1.0, 1.0); + /* Emit quads */ for (list = texture->tiles; list != NULL; list = list->next) { Tile *tile = list->data; - if ((!clip || region_intersects_rect (clip, &tile->geometry))) - { - int translated_x = tile->geometry.x + x; - int translated_y = tile->geometry.y + y; - - glBindTexture (GL_TEXTURE_2D, tile->texture); -#if 0 - g_print ("bound %p, %d\n", tile, tile->texture); -#endif - - dump_error ("glbindtexture"); - - glBegin (GL_QUADS); - - /* corner 1 */ -#if 0 - glColor4f (1.0, 0.2, 0.2, alpha); -#endif - glTexCoord2f (0.0, 0.0); - glVertex3i (translated_x, translated_y, 0); - - /* corner 2 */ -#if 0 - glColor4f (0.0, 0.4, 0.2, alpha); -#endif - glTexCoord2f (1.0, 0.0); - glVertex3i (translated_x + tile->geometry.width, translated_y, 0); - - /* corner 3 */ -#if 0 - glColor4f (0.0, 0.2, 0.8, alpha); -#endif - glTexCoord2f (1.0, 1.0); - glVertex3i (translated_x + tile->geometry.width, translated_y + tile->geometry.height, 0); - - /* corner 4 */ -#if 0 - glColor4f (0.8, 0.8, 0.0, alpha); -#endif - glTexCoord2f (0.0, 1.0); - glVertex3i (translated_x, translated_y + tile->geometry.height, 0); - - glEnd (); - dump_error ("glEnd"); - - unset_clip_region (); - - glColor4f (0.8, 0.0, 0.8, 0.2); - - glDisable (GL_TEXTURE_2D); - glBegin (GL_QUADS); - glVertex3i (translated_x, translated_y, 0); - glVertex3i (translated_x + tile->geometry.width, translated_y, 0); - glVertex3i (translated_x + tile->geometry.width, - translated_y + tile->geometry.height, 0); - glVertex3i (translated_x, translated_y + tile->geometry.height, 0); - glEnd (); - glEnable (GL_TEXTURE_2D); - - set_clip_region (clip, x, y); - glColor4f (1.0, 1.0, 1.0, alpha); - } - - else - { -#if 0 - int translated_x = tile->geometry.x + x; - int translated_y = tile->geometry.y + y; - - print_gdk_region ("clip", clip); - - glColor4f (g_random_double(), - g_random_double(), - g_random_double(), 0.2); - - glDisable (GL_TEXTURE_2D); - glBegin (GL_QUADS); - glVertex3i (translated_x, translated_y, 0); - glVertex3i (translated_x + tile->geometry.width, translated_y, 0); - glVertex3i (translated_x + tile->geometry.width, - translated_y + tile->geometry.height, 0); - glVertex3i (translated_x, translated_y + tile->geometry.height, 0); - glEnd (); - glEnable (GL_TEXTURE_2D); - glColor4f (1.0, 1.0, 1.0, alpha); -#endif - } + draw_tile (screen, tile, x, y, clip); } glDisable (GL_TEXTURE_2D); @@ -769,9 +797,9 @@ lmc_texture_draw (LmcTexture *texture, } #endif +#if 0 unset_clip_region (); - - out: +#endif glPopAttrib (); } diff --git a/src/lmctexture.h b/src/lmctexture.h index 4ceac076..bebe9785 100644 --- a/src/lmctexture.h +++ b/src/lmctexture.h @@ -8,16 +8,24 @@ #include <X11/Xutil.h> /* For Region */ #include <GL/gl.h> /* For GLuint */ +#include "config.h" +#include "screen.h" + G_BEGIN_DECLS typedef struct _LmcTexture LmcTexture; +void lmc_texture_set_deformation (LmcTexture *texture, + LmcDeformationFunc func, + void *data); + LmcTexture* lmc_texture_new (LmcBits *bits); LmcTexture* lmc_texture_ref (LmcTexture *texture); void lmc_texture_unref (LmcTexture *texture); void lmc_texture_update_rect (LmcTexture *texture, GdkRectangle *rect); -void lmc_texture_draw (LmcTexture *texture, +void lmc_texture_draw (MetaScreen *screen, + LmcTexture *texture, double alpha, int x, int y, diff --git a/src/lmctypes.h b/src/lmctypes.h index 96d8ac42..45c6739e 100644 --- a/src/lmctypes.h +++ b/src/lmctypes.h @@ -8,6 +8,8 @@ G_BEGIN_DECLS typedef struct _LmcBorderInfo LmcBorderInfo; typedef struct _LmcPropertyValue LmcPropertyValue; +typedef struct _LmcPixel LmcPixel; +typedef struct _LmcPoint LmcPoint; struct _LmcBorderInfo { @@ -21,7 +23,7 @@ struct _LmcPropertyValue int format; /* 8, 16, 32 */ union { - unsigned char *b; + char *b; short *s; long *l; } data; @@ -29,6 +31,23 @@ struct _LmcPropertyValue unsigned long n_items; /* Number of 8, 16, or 32 bit quantities */ }; +struct _LmcPixel { + guchar red; + guchar green; + guchar blue; + guchar alpha; +}; + +struct _LmcPoint { + double x; + double y; +}; + +typedef void (*LmcDeformationFunc) (int u, int v, + int x, int y, int width, int height, + int *deformed_x, int *deformed_y, + void *data); + G_END_DECLS #endif /* __LMC_TYPES_H__ */ |