From 6ebe6bf466a6c4d25648a26cc0ca609eb54cc9ab Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Sun, 6 Aug 2000 00:26:34 +0000 Subject: [PATCH] cleaing up code.. loosk much nicer now SVN revision: 3029 --- legacy/evas/src/evas_gl_routines.c | 560 ++++++++++++++++++----------- legacy/evas/src/evas_gl_routines.h | 90 +++-- legacy/evas/test/evas_test.c | 16 +- 3 files changed, 427 insertions(+), 239 deletions(-) diff --git a/legacy/evas/src/evas_gl_routines.c b/legacy/evas/src/evas_gl_routines.c index 4b6f9c7e65..b47df22e7b 100644 --- a/legacy/evas/src/evas_gl_routines.c +++ b/legacy/evas/src/evas_gl_routines.c @@ -10,6 +10,13 @@ static int __evas_gl_configuration[] = None }; +static void __evas_gl_image_copy_image_rect_to_texture(Evas_GL_Image *im, int x, int y, int w, int h, int tw, int th, GLuint texture); +static void __evas_gl_image_move_state_data_to_texture(Evas_GL_Image *im); +static void __evas_gl_image_calc_tex_and_poly(Evas_GL_Image *im, int x, double *x1, double *x2, int *tx, int *txx, double *dtx, double *dtxx, int tw, int w, int edge); +static void __evas_gl_image_set_context_for_dest(Evas_GL_Image *im, Display *disp, Window w, int win_w, int win_h); +static Evas_GL_Image *__evas_gl_create_image(void); +static Evas_GL_Image *__evas_gl_image_create_from_file(Display *disp, char *file); +static void __evas_gl_image_destroy(Evas_GL_Image *im); static XVisualInfo *__evas_vi = NULL; static GLXContext __evas_gl_cx = 0; @@ -18,8 +25,37 @@ static Evas_List __evas_images = NULL; static int __evas_image_cache_max = 16 *1024 * 1024; static int __evas_image_cache_used = 0; -void -__evas_gl_copy_image_rect_to_texture(Evas_GL_Image *im, int x, int y, + + + + + + + + + + + + + + + + + + + + + + + + + +/*****************************************************************************/ +/* image internals ***********************************************************/ +/*****************************************************************************/ + +static void +__evas_gl_image_copy_image_rect_to_texture(Evas_GL_Image *im, int x, int y, int w, int h, int tw, int th, GLuint texture) { @@ -53,13 +89,13 @@ __evas_gl_copy_image_rect_to_texture(Evas_GL_Image *im, int x, int y, free(data); } -void -__evas_gl_move_state_data_to_texture(Evas_GL_Image *im) +static void +__evas_gl_image_move_state_data_to_texture(Evas_GL_Image *im) { int i, x, y; XSetWindowAttributes att; int image_data = 0; - Imlib_Image image; + Imlib_Image image = NULL; if ((!im->data) && (im->file)) { @@ -153,7 +189,7 @@ __evas_gl_move_state_data_to_texture(Evas_GL_Image *im) if (y == 0) hh--; if (y == (im->texture.h - 1)) hh--; - __evas_gl_copy_image_rect_to_texture(im, xx, yy, ww, hh, tw, th, + __evas_gl_image_copy_image_rect_to_texture(im, xx, yy, ww, hh, tw, th, im->texture.textures[i]); __evas_image_cache_used += (tw * th * 4); } @@ -169,8 +205,9 @@ __evas_gl_move_state_data_to_texture(Evas_GL_Image *im) } } -void __evas_calc_tex_and_poly(Evas_GL_Image *im, int x, double *x1, double *x2, - int *tx, int *txx, double *dtx, double *dtxx, int tw, int w, int edge) +static void +__evas_gl_image_calc_tex_and_poly(Evas_GL_Image *im, int x, double *x1, double *x2, + int *tx, int *txx, double *dtx, double *dtxx, int tw, int w, int edge) { if ((x == 0) && (tw > 1)) { @@ -212,8 +249,9 @@ void __evas_calc_tex_and_poly(Evas_GL_Image *im, int x, double *x1, double *x2, *x2 = (double)w; } -void __evas_gl_set_conect_for_dest(Evas_GL_Image *im, Display *disp, Window w, - int win_w, int win_h) +static void +__evas_gl_image_set_context_for_dest(Evas_GL_Image *im, Display *disp, Window w, + int win_w, int win_h) { if (im->buffer.dest != w) { @@ -254,18 +292,91 @@ void __evas_gl_set_conect_for_dest(Evas_GL_Image *im, Display *disp, Window w, } } -void __evas_gl_render_to_window(Evas_GL_Image *im, - Display *disp, Window w, int win_w, int win_h, - int src_x, int src_y, int src_w, int src_h, - int dst_x, int dst_y, int dst_w, int dst_h) +static Evas_GL_Image * +__evas_gl_create_image(void) +{ + Evas_GL_Image *im; + + im = malloc(sizeof(Evas_GL_Image)); + memset(im, 0, sizeof(Evas_GL_Image)); + return im; +} + +static Evas_GL_Image * +__evas_gl_image_create_from_file(Display *disp, char *file) +{ + Evas_GL_Image *im; + Imlib_Image i; + + if (!file) return NULL; + im = __evas_gl_create_image(); + im->file = strdup(file); + i = imlib_load_image(file); + if (i) + { + imlib_context_set_image(i); + im->w = imlib_image_get_width(); + im->h = imlib_image_get_height(); + im->alpha = imlib_image_has_alpha(); + imlib_free_image(); + } + else + { + im->w = 0; + im->h = 0; + } + im->data = NULL; + im->texture.max_size = 256; + im->texture.w = 0; + im->texture.h = 0; + im->texture.edge_w = 0; + im->texture.edge_h = 0; + im->texture.textures = NULL; + + __evas_gl_init(disp); + im->context = __evas_gl_cx; + im->buffer.display = disp; + im->buffer.colormap = __evas_gl_get_colormap(disp); + im->buffer.visual_info = __evas_vi; + im->buffer.window = 0; + im->buffer.dest = 0; + im->buffer.dest_w = 0; + im->buffer.dest_h = 0; + + im->references = 1; + + return im; +} + +static void +__evas_gl_image_destroy(Evas_GL_Image *im) +{ + if (im->file) free(im->file); + if (im->data) free(im->data); + if (im->texture.textures) + { + glDeleteTextures(im->texture.w * im->texture.h, im->texture.textures); + free(im->texture.textures); + } + free(im); +} + +/*****************************************************************************/ +/* image externals ***********************************************************/ +/*****************************************************************************/ + +void +__evas_gl_image_draw(Evas_GL_Image *im, + Display *disp, Window w, int win_w, int win_h, + int src_x, int src_y, int src_w, int src_h, + int dst_x, int dst_y, int dst_w, int dst_h) { int x, y, i; double dx, dy, dw, dh; - int done = 1; if (im->state != EVAS_STATE_TEXTURE) - __evas_gl_move_state_data_to_texture(im); - __evas_gl_set_conect_for_dest(im, disp, w, win_w, win_h); + __evas_gl_image_move_state_data_to_texture(im); + __evas_gl_image_set_context_for_dest(im, disp, w, win_w, win_h); /* project src and dst rects to overall dest rect */ dw = (((double)dst_w * (double)im->w)/ (double)src_w); dx = (double)dst_x - (((double)dst_w * (double)src_x)/ (double)src_w); @@ -281,14 +392,14 @@ void __evas_gl_render_to_window(Evas_GL_Image *im, double dtx, dtxx, dty, dtyy; - __evas_calc_tex_and_poly(im, x, &x1, &x2, &tx, &txx, - &dtx, &dtxx, - im->texture.w, im->w, - im->texture.edge_w); - __evas_calc_tex_and_poly(im, y, &y1, &y2, &ty, &tyy, - &dty, &dtyy, - im->texture.h, im->h, - im->texture.edge_h); + __evas_gl_image_calc_tex_and_poly(im, x, &x1, &x2, &tx, &txx, + &dtx, &dtxx, + im->texture.w, im->w, + im->texture.edge_w); + __evas_gl_image_calc_tex_and_poly(im, y, &y1, &y2, &ty, &tyy, + &dty, &dtyy, + im->texture.h, im->h, + im->texture.edge_h); x1 = dx + ((x1 * dw) / (double)im->w); y1 = dy + ((y1 * dh) / (double)im->h); x2 = dx + ((x2 * dw) / (double)im->w); @@ -306,15 +417,230 @@ void __evas_gl_render_to_window(Evas_GL_Image *im, } Evas_GL_Image * -__evas_gl_create_image(void) -{ +__evas_gl_image_new_from_file(Display *disp, char *file) +{ Evas_GL_Image *im; + Evas_List l; + + for (l = __evas_images; l; l = l->next) + { + im = l->data; + + if (((im->file) && (im->buffer.display == disp)) && + (!strcmp(im->file, file))) + { + if (l != __evas_images) + { + __evas_images = evas_list_remove(__evas_images, im); + __evas_images = evas_list_prepend(__evas_images, im); + } + im->references++; + return im; + } + } + + im = __evas_gl_image_create_from_file(disp, file); + __evas_images = evas_list_prepend(__evas_images, im); - im = malloc(sizeof(Evas_GL_Image)); - memset(im, 0, sizeof(Evas_GL_Image)); return im; } +void +__evas_gl_image_free(Evas_GL_Image *im) +{ + im->references--; + if (im->references <= 0) + __evas_gl_image_cache_flush(im->buffer.display); +} + +void +__evas_gl_image_cache_flush(Display *disp) +{ + while (__evas_image_cache_used > __evas_image_cache_max) + { + Evas_GL_Image *im = NULL, *im_last; + Evas_List l; + + im_last = NULL; + for (l = __evas_images; l; l = l->next) + { + im = l->data; + + if (im->references <= 0) + im_last = im; + } + if (im_last) + { + __evas_images = evas_list_remove(__evas_images, im_last); + __evas_gl_image_destroy(im_last); + } + } + disp = NULL; +} + +void +__evas_gl_image_cache_empty(Display *disp) +{ + Evas_GL_Image *im = NULL, *im_last; + Evas_List l; + im_last = (Evas_GL_Image *)1; + + while (im_last) + { + im_last = NULL; + for (l = __evas_images; l; l = l->next) + { + im = l->data; + + if (im->references <= 0) + im_last = im; + } + if (im_last) + { + __evas_images = evas_list_remove(__evas_images, im_last); + __evas_gl_image_destroy(im_last); + } + } + disp = NULL; +} + +void +__evas_gl_image_cache_set_size(Display *disp, int size) +{ + __evas_image_cache_max = size; + __evas_gl_image_cache_flush(disp); +} + +int +__evas_gl_image_cache_get_size(Display *disp) +{ + return __evas_image_cache_max; + disp = NULL; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +/*****************************************************************************/ +/* font internals ************************************************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/* font externals ************************************************************/ +/*****************************************************************************/ + +Evas_GL_Font * +__evas_gl_text_font_load(Display *disp, char *font, int size) +{ +} + +void +__evas_gl_text_font_free(Evas_GL_Font *fn) +{ +} + +void +__evas_gl_text_font_add_path(char *path) +{ +} + +void +__evas_gl_text_font_del_path(char *path) +{ +} + +char ** +__evas_gl_text_font_list_paths(int *count) +{ +} + +void +__evas_gl_text_draw(Evas_GL_Font *fn, Display *disp, Window win, int x, int y, + char *text, int r, int g, int b, int a) +{ +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +/*****************************************************************************/ +/* general externals *********************************************************/ +/*****************************************************************************/ + +void +__evas_gl_sync(Display *disp) +{ + glXWaitGL(); + XSync(disp, False); +} + +void +__evas_gl_flush_draw(Display *disp, Window win) +{ + glXSwapBuffers(disp, win); +} + int __evas_gl_capable(Display *disp) { @@ -370,179 +696,3 @@ __evas_gl_init(Display *disp) /* __evas_gl_cx = glXCreateContext(disp, __evas_vi, NULL, GL_FALSE);*/ } -Evas_GL_Image * -__evas_gl_image_create_from_file(Display *disp, char *file) -{ - Evas_GL_Image *im; - Imlib_Image i; - - if (!file) return NULL; - im = __evas_gl_create_image(); - im->file = strdup(file); - i = imlib_load_image(file); - if (i) - { - imlib_context_set_image(i); - im->w = imlib_image_get_width(); - im->h = imlib_image_get_height(); - im->alpha = imlib_image_has_alpha(); - imlib_free_image(); - } - else - { - im->w = 0; - im->h = 0; - } - im->data = NULL; - im->texture.max_size = 256; - im->texture.w = 0; - im->texture.h = 0; - im->texture.edge_w = 0; - im->texture.edge_h = 0; - im->texture.textures = NULL; - - __evas_gl_init(disp); - im->context = __evas_gl_cx; - im->buffer.display = disp; - im->buffer.colormap = __evas_gl_get_colormap(disp); - im->buffer.visual_info = __evas_vi; - im->buffer.window = 0; - im->buffer.dest = 0; - im->buffer.dest_w = 0; - im->buffer.dest_h = 0; - - im->references = 1; - - return im; -} - -Evas_GL_Image * -__evas_gl_image_new_from_file(Display *disp, char *file) -{ - Evas_GL_Image *im; - Evas_List l; - - for (l = __evas_images; l; l = l->next) - { - im = l->data; - - if (((im->file) && (im->buffer.display == disp)) && - (!strcmp(im->file, file))) - { - if (l != __evas_images) - { - __evas_images = evas_list_remove(__evas_images, im); - __evas_images = evas_list_prepend(__evas_images, im); - } - im->references++; - return im; - } - } - - im = __evas_gl_image_create_from_file(disp, file); - __evas_images = evas_list_prepend(__evas_images, im); - - return im; -} - -void -__evas_gl_image_free(Evas_GL_Image *im) -{ - im->references--; - if (im->references <= 0) - __evas_gl_image_cache_flush(im->buffer.display); -} - -void -__evas_gl_image_destroy(Evas_GL_Image *im) -{ - if (im->file) free(im->file); - if (im->data) free(im->data); - if (im->texture.textures) - { - glDeleteTextures(im->texture.w * im->texture.h, im->texture.textures); - free(im->texture.textures); - } - free(im); -} - -void -__evas_gl_image_cache_flush(Display *disp) -{ - while (__evas_image_cache_used > __evas_image_cache_max) - { - Evas_GL_Image *im = NULL, *im_last; - Evas_List l; - - im_last = NULL; - for (l = __evas_images; l; l = l->next) - { - im = l->data; - - if (im->references <= 0) - im_last = im; - } - if (im_last) - { - __evas_images = evas_list_remove(__evas_images, im_last); - __evas_gl_image_destroy(im_last); - } - } -} - -void -__evas_gl_image_cache_empty(Display *disp) -{ - Evas_GL_Image *im = NULL, *im_last; - Evas_List l; - im_last = (Evas_GL_Image *)1; - - while (im_last) - { - im_last = NULL; - for (l = __evas_images; l; l = l->next) - { - im = l->data; - - if (im->references <= 0) - im_last = im; - } - if (im_last) - { - __evas_images = evas_list_remove(__evas_images, im_last); - __evas_gl_image_destroy(im_last); - } - } -} - -void -__evas_gl_image_cache_set_size(Display *disp, int size) -{ - __evas_image_cache_max = size; - __evas_gl_image_cache_flush(disp); -} - -int -__evas_gl_image_cache_get_size(Display *disp) -{ - return __evas_image_cache_max; -} - -void -__evas_gl_sync(Display *disp) -{ - glXWaitGL(); - XSync(disp, False); -} - -void -__evas_gl_flush_draw(Display *disp, Window win) -{ - glXSwapBuffers(disp, win); -} - -void -__evas_gl_draw_rectangle(Display *disp, Window win, int x, int y, int w, int h, - int r, int g, int b, int a) -{ -} diff --git a/legacy/evas/src/evas_gl_routines.h b/legacy/evas/src/evas_gl_routines.h index 37059177ed..0381234108 100644 --- a/legacy/evas/src/evas_gl_routines.h +++ b/legacy/evas/src/evas_gl_routines.h @@ -17,6 +17,7 @@ #include "Evas.h" typedef struct _evas_gl_image Evas_GL_Image; +typedef struct _evas_gl_font Evas_GL_Font; typedef enum _evas_gl_image_state Evas_GL_Image_State; enum _evas_gl_image_state @@ -55,33 +56,64 @@ struct _evas_gl_image int references; }; -void __evas_gl_copy_image_rect_to_texture(Evas_GL_Image *im, int x, int y, - int w, int h, int tw, int th, - GLuint texture); -void __evas_gl_move_state_data_to_texture(Evas_GL_Image *im); -void __evas_calc_tex_and_poly(Evas_GL_Image *im, int x, double *x1, double *x2, - int *tx, int *txx, double *dtx, double *dtxx, int tw, int w, int edge); -void __evas_gl_set_conect_for_dest(Evas_GL_Image *im, Display *disp, Window w, - int win_w, int win_h); -void __evas_gl_render_to_window(Evas_GL_Image *im, - Display *disp, Window w, int win_w, int win_h, - int src_x, int src_y, int src_w, int src_h, - int dst_x, int dst_y, int dst_w, int dst_h); -Evas_GL_Image * __evas_gl_create_image(void); -int __evas_gl_capable(Display *disp); -Visual * __evas_gl_get_visual(Display *disp); +struct _evas_gl_font +{ + char *file; + int size; + + GLXContext context; + struct + { + Display *display; + XVisualInfo *visual_info; + Colormap colormap; + Window window, dest; + int dest_w, dest_h; + } buffer; + int references; +}; + +/***************/ +/* image stuff */ +/***************/ +Evas_GL_Image *__evas_gl_image_new_from_file(Display *disp, char *file); +void __evas_gl_image_free(Evas_GL_Image *im); +void __evas_gl_image_cache_flush(Display *disp); +void __evas_gl_image_cache_empty(Display *disp); +void __evas_gl_image_cache_set_size(Display *disp, int size); +int __evas_gl_image_cache_get_size(Display *disp); +void __evas_gl_image_draw(Evas_GL_Image *im, Display *disp, Window w, int win_w, int win_h, int src_x, int src_y, int src_w, int src_h, int dst_x, int dst_y, int dst_w, int dst_h); + +/********/ +/* text */ +/********/ +Evas_GL_Font *__evas_gl_text_font_load(Display *disp, char *font, int size); +void __evas_gl_text_font_free(Evas_GL_Font *fn); +void __evas_gl_text_font_add_path(char *path); +void __evas_gl_text_font_del_path(char *path); +char **__evas_gl_text_font_list_paths(int *count); +void __evas_gl_text_draw(Evas_GL_Font *fn, Display *disp, Window win, int x, int y, char *text, int r, int g, int b, int a); + +/**************/ +/* rectangles */ +/**************/ + +/*********/ +/* lines */ +/*********/ + +/*************/ +/* gradients */ +/*************/ + +/***********/ +/* drawing */ +/***********/ +void __evas_gl_init(Display *disp); +int __evas_gl_capable(Display *disp); +void __evas_gl_flush_draw(Display *disp, Window win); +void __evas_gl_sync(Display *disp); +Visual *__evas_gl_get_visual(Display *disp); XVisualInfo *__evas_gl_get_visual_info(Display *disp); -Colormap __evas_gl_get_colormap(Display *disp); -void __evas_gl_init(Display *disp); -Evas_GL_Image *__evas_gl_image_create_from_file(Display *disp, char *file); -Evas_GL_Image * __evas_gl_image_new_from_file(Display *disp, char *file); -void __evas_gl_image_free(Evas_GL_Image *im); -void __evas_gl_image_destroy(Evas_GL_Image *im); -void __evas_gl_image_cache_flush(Display *disp); -void __evas_gl_image_cache_empty(Display *disp); -void __evas_gl_image_cache_set_size(Display *disp, int size); -int __evas_gl_image_cache_get_size(Display *disp); -void __evas_gl_sync(Display *disp); -void __evas_gl_flush_draw(Display *disp, Window win); -void __evas_gl_draw_rectangle(Display *disp, Window win, int x, int y, int w, int h, - int r, int g, int b, int a); +Colormap __evas_gl_get_colormap(Display *disp); + diff --git a/legacy/evas/test/evas_test.c b/legacy/evas/test/evas_test.c index 8952dd36ab..5f4cee2c47 100644 --- a/legacy/evas/test/evas_test.c +++ b/legacy/evas/test/evas_test.c @@ -2,6 +2,8 @@ #include "../src/evas_gl_routines.h" #include +double get_time(void); + double get_time(void) { @@ -60,13 +62,14 @@ main(int argc, char **argv) printf("cannot find images!\n"); exit(1); } + t1 = 0; for(;;) { - int x, y, j, k; + int j, k; if (a == 0) t1 = get_time(); - __evas_gl_render_to_window(bg, d, win, win_w, win_h, + __evas_gl_image_draw(bg, d, win, win_w, win_h, 0, 0, bg->w, bg->h, 0, 0, win_w, win_h); for (k = 0; k < 4; k++) @@ -77,13 +80,13 @@ main(int argc, char **argv) xx = (((k + 1) * a) / 2) % win_w; yy = 0; if (k == 2) - __evas_gl_render_to_window(l, d, win, win_w, win_h, + __evas_gl_image_draw(l, d, win, win_w, win_h, 0, 0, l->w, l->h, (win_w - l->w) / 2, (win_h - l->h) /2, l->w, l->h); - __evas_gl_render_to_window(i[j], d, win, win_w, win_h, + __evas_gl_image_draw(i[j], d, win, win_w, win_h, 0, 0, i[j]->w, i[j]->h, xx, yy, win_w, win_h); - __evas_gl_render_to_window(i[j], d, win, win_w, win_h, + __evas_gl_image_draw(i[j], d, win, win_w, win_h, 0, 0, i[j]->w, i[j]->h, xx - win_w, yy, win_w, win_h); } @@ -107,4 +110,7 @@ main(int argc, char **argv) { printf("Your X server is unable to do GLX - no go buddy.\n"); } + argv = NULL; + argc = 0; + return 0; }