From c802275f0537d3fac07660a127b5872d1fe35af4 Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Sun, 6 Aug 2000 02:06:24 +0000 Subject: [PATCH] framework for imlib2 backend. - ne3ed at least another sample..... SVN revision: 3033 --- legacy/evas/src/Makefile.am | 2 + legacy/evas/src/evas_gl_routines.c | 86 +++++---- legacy/evas/src/evas_gl_routines.h | 19 +- legacy/evas/src/evas_imlib_routines.c | 255 ++++++++++++++++++++++++++ legacy/evas/src/evas_imlib_routines.h | 66 +++++++ legacy/evas/test/evas_test.c | 6 +- 6 files changed, 387 insertions(+), 47 deletions(-) create mode 100644 legacy/evas/src/evas_imlib_routines.c create mode 100644 legacy/evas/src/evas_imlib_routines.h diff --git a/legacy/evas/src/Makefile.am b/legacy/evas/src/Makefile.am index e0c583ca31..4c67244fb7 100644 --- a/legacy/evas/src/Makefile.am +++ b/legacy/evas/src/Makefile.am @@ -36,6 +36,7 @@ evas_events.c \ evas_gl_routines.c \ evas_gradient.c \ evas_image.c \ +evas_imlib_routines.c \ evas_line.c \ evas_list.c \ evas_main.c \ @@ -45,6 +46,7 @@ evas_rectangle.c \ evas_render.c \ evas_text.c \ evas_gl_routines.h \ +evas_imlib_routines.h \ Evas.h libevas_la_LIBADD = $(LIBS_ALL) diff --git a/legacy/evas/src/evas_gl_routines.c b/legacy/evas/src/evas_gl_routines.c index b47df22e7b..83524cc9d1 100644 --- a/legacy/evas/src/evas_gl_routines.c +++ b/legacy/evas/src/evas_gl_routines.c @@ -17,6 +17,7 @@ static void __evas_gl_image_set_context_for_dest(Evas_GL_Image *im, Di 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 void __evas_gl_image_cache_flush(Display *disp); static XVisualInfo *__evas_vi = NULL; static GLXContext __evas_gl_cx = 0; @@ -336,7 +337,7 @@ __evas_gl_image_create_from_file(Display *disp, char *file) __evas_gl_init(disp); im->context = __evas_gl_cx; im->buffer.display = disp; - im->buffer.colormap = __evas_gl_get_colormap(disp); + im->buffer.colormap = __evas_gl_get_colormap(disp, 0); im->buffer.visual_info = __evas_vi; im->buffer.window = 0; im->buffer.dest = 0; @@ -361,6 +362,31 @@ __evas_gl_image_destroy(Evas_GL_Image *im) free(im); } +static 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; +} + /*****************************************************************************/ /* image externals ***********************************************************/ /*****************************************************************************/ @@ -453,31 +479,6 @@ __evas_gl_image_free(Evas_GL_Image *im) __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) { @@ -559,7 +560,7 @@ __evas_gl_image_cache_get_size(Display *disp) /*****************************************************************************/ Evas_GL_Font * -__evas_gl_text_font_load(Display *disp, char *font, int size) +__evas_gl_text_font_new(Display *disp, char *font, int size) { } @@ -583,6 +584,21 @@ __evas_gl_text_font_list_paths(int *count) { } +void +__evas_gl_text_cache_empty(Display *disp) +{ +} + +void +__evas_gl_text_cache_set_size(Display *disp, int size) +{ +} + +int +__evas_gl_text_cache_get_size(Display *disp) +{ +} + 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) @@ -649,36 +665,36 @@ __evas_gl_capable(Display *disp) } Visual * -__evas_gl_get_visual(Display *disp) +__evas_gl_get_visual(Display *disp, int screen) { static Display *d = NULL; if (d != disp) { d = disp; - __evas_vi = glXChooseVisual(disp, DefaultScreen(disp), __evas_gl_configuration); + __evas_vi = glXChooseVisual(disp, screen, __evas_gl_configuration); } return __evas_vi->visual; } XVisualInfo * -__evas_gl_get_visual_info(Display *disp) +__evas_gl_get_visual_info(Display *disp, int screen) { - __evas_gl_get_visual(disp); + __evas_gl_get_visual(disp, screen); return __evas_vi; } Colormap -__evas_gl_get_colormap(Display *disp) +__evas_gl_get_colormap(Display *disp, int screen) { static Display *d = NULL; static Colormap cmap = 0; - if (!__evas_vi) __evas_gl_get_visual(disp); + if (!__evas_vi) __evas_gl_get_visual(disp, screen); if (d != disp) { d = disp; - cmap = XCreateColormap(disp, RootWindow(disp, DefaultScreen(disp)), __evas_vi->visual, 0); + cmap = XCreateColormap(disp, RootWindow(disp, screen), __evas_vi->visual, 0); } return cmap; } @@ -689,7 +705,7 @@ __evas_gl_init(Display *disp) if (__evas_gl_cx) return; if (!__evas_gl_capable(disp)) return; - __evas_gl_get_visual(disp); + __evas_gl_get_visual(disp, 0); /* direct rendering client */ __evas_gl_cx = glXCreateContext(disp, __evas_vi, NULL, GL_TRUE); /* GLX indirect */ diff --git a/legacy/evas/src/evas_gl_routines.h b/legacy/evas/src/evas_gl_routines.h index 0381234108..25d7c369b2 100644 --- a/legacy/evas/src/evas_gl_routines.h +++ b/legacy/evas/src/evas_gl_routines.h @@ -12,13 +12,12 @@ #include #include #include -#include #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; +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 { @@ -78,7 +77,6 @@ struct _evas_gl_font /***************/ 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); @@ -87,11 +85,14 @@ void __evas_gl_image_draw(Evas_GL_Image *im, Display *disp, Window w, /********/ /* text */ /********/ -Evas_GL_Font *__evas_gl_text_font_load(Display *disp, char *font, int size); +Evas_GL_Font *__evas_gl_text_font_new(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_cache_empty(Display *disp); +void __evas_gl_text_cache_set_size(Display *disp, int size); +int __evas_gl_text_cache_get_size(Display *disp); 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); /**************/ @@ -113,7 +114,7 @@ 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); +Visual *__evas_gl_get_visual(Display *disp, int screen); +XVisualInfo *__evas_gl_get_visual_info(Display *disp, int screen); +Colormap __evas_gl_get_colormap(Display *disp, int screen); diff --git a/legacy/evas/src/evas_imlib_routines.c b/legacy/evas/src/evas_imlib_routines.c new file mode 100644 index 0000000000..e611bbd52c --- /dev/null +++ b/legacy/evas/src/evas_imlib_routines.c @@ -0,0 +1,255 @@ +#include "evas_imlib_routines.h" + +/*****************************************************************************/ +/* image internals ***********************************************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/* image externals ***********************************************************/ +/*****************************************************************************/ + +Evas_Imlib_Image * +__evas_imlib_image_new_from_file(Display *disp, char *file) +{ + return (Evas_Imlib_Image *)imlib_load_image(file); +} + +void +__evas_imlib_image_free(Evas_Imlib_Image *im) +{ + imlib_context_set_image((Imlib_Image)im); + imlib_free_image(); +} + +void +__evas_imlib_image_cache_flush(Display *disp) +{ + int size; + + size = imlib_get_cache_size(); + imlib_set_cache_size(0); + imlib_set_cache_size(size); +} + +void +__evas_imlib_image_cache_empty(Display *disp) +{ + int size; + + size = imlib_get_cache_size(); + imlib_set_cache_size(0); + imlib_set_cache_size(size); +} + +void +__evas_imlib_image_cache_set_size(Display *disp, int size) +{ + imlib_set_cache_size(size); +} + +int +__evas_imlib_image_cache_get_size(Display *disp) +{ + return imlib_get_cache_size(); +} + +void +__evas_imlib_image_draw(Evas_Imlib_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) +{ + +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +/*****************************************************************************/ +/* font internals ************************************************************/ +/*****************************************************************************/ + +/*****************************************************************************/ +/* font externals ************************************************************/ +/*****************************************************************************/ + +Evas_Imlib_Font * +__evas_imlib_text_font_new(Display *disp, char *font, int size) +{ + char buf[4096]; + + sprintf(buf, "%s/%i", font, size); + return (Evas_Imlib_Font *)imlib_load_font(buf); +} + +void +__evas_imlib_text_font_free(Evas_Imlib_Font *fn) +{ + imlib_context_set_font((Imlib_Font)fn); + imlib_free_font(); +} + +void +__evas_imlib_text_font_add_path(char *path) +{ + imlib_add_path_to_font_path(path); +} + +void +__evas_imlib_text_font_del_path(char *path) +{ + imlib_remove_path_from_font_path(path); +} + +char ** +__evas_imlib_text_font_list_paths(int *count) +{ + return imlib_list_font_path(count); +} + +void +__evas_imlib_text_cache_empty(Display *disp) +{ + int size; + + size = imlib_get_font_cache_size(); + imlib_set_font_cache_size(0); + imlib_set_font_cache_size(size); +} + +void +__evas_imlib_text_cache_set_size(Display *disp, int size) +{ + imlib_set_font_cache_size(size); +} + +int +__evas_imlib_text_cache_get_size(Display *disp) +{ + return imlib_get_font_cache_size(); +} + +void +__evas_imlib_text_draw(Evas_Imlib_Font *fn, Display *disp, Window win, int x, int y, + char *text, int r, int g, int b, int a) +{ +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +/*****************************************************************************/ +/* general externals *********************************************************/ +/*****************************************************************************/ + +void +__evas_imlib_sync(Display *disp) +{ + XSync(disp, False); +} + +void +__evas_imlib_flush_draw(Display *disp, Window win) +{ + imlib_context_set_display(disp); +} + +int +__evas_imlib_capable(Display *disp) +{ + return 1; +} + +Visual * +__evas_imlib_get_visual(Display *disp, int screen) +{ + int depth; + return imlib_get_best_visual(disp, screen, &depth); +} + +XVisualInfo * +__evas_imlib_get_visual_info(Display *disp, int screen) +{ + static XVisualInfo *vi = NULL; + XVisualInfo vi_template; + int n; + + if (vi) return vi; + vi_template.visualid = (__evas_imlib_get_visual(disp, screen))->visualid; + vi_template.screen = screen; + vi = XGetVisualInfo(disp, VisualIDMask | VisualScreenMask, &vi_template ,&n); + return vi; +} + +Colormap +__evas_imlib_get_colormap(Display *disp, int screen) +{ + return DefaultColormap(disp, screen); +} + +void +__evas_imlib_init(Display *disp) +{ + imlib_context_set_display(disp); +} + diff --git a/legacy/evas/src/evas_imlib_routines.h b/legacy/evas/src/evas_imlib_routines.h new file mode 100644 index 0000000000..e8a0eb6029 --- /dev/null +++ b/legacy/evas/src/evas_imlib_routines.h @@ -0,0 +1,66 @@ +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "Evas.h" + +#include + +typedef void Evas_Imlib_Image; +typedef void Evas_Imlib_Font; + +/***************/ +/* image stuff */ +/***************/ +Evas_Imlib_Image *__evas_imlib_image_new_from_file(Display *disp, char *file); +void __evas_imlib_image_free(Evas_Imlib_Image *im); +void __evas_imlib_image_cache_empty(Display *disp); +void __evas_imlib_image_cache_set_size(Display *disp, int size); +int __evas_imlib_image_cache_get_size(Display *disp); +void __evas_imlib_image_draw(Evas_Imlib_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_Imlib_Font *__evas_imlib_text_font_new(Display *disp, char *font, int size); +void __evas_imlib_text_font_free(Evas_Imlib_Font *fn); +void __evas_imlib_text_font_add_path(char *path); +void __evas_imlib_text_font_del_path(char *path); +char **__evas_imlib_text_font_list_paths(int *count); +void __evas_imlib_text_cache_empty(Display *disp); +void __evas_imlib_text_cache_set_size(Display *disp, int size); +int __evas_imlib_text_cache_get_size(Display *disp); +void __evas_imlib_text_draw(Evas_Imlib_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_imlib_init(Display *disp); +int __evas_imlib_capable(Display *disp); +void __evas_imlib_flush_draw(Display *disp, Window win); +void __evas_imlib_sync(Display *disp); +Visual *__evas_imlib_get_visual(Display *disp, int screen); +XVisualInfo *__evas_imlib_get_visual_info(Display *disp, int screen); +Colormap __evas_imlib_get_colormap(Display *disp, int screen); + diff --git a/legacy/evas/test/evas_test.c b/legacy/evas/test/evas_test.c index 5f4cee2c47..3895a48b16 100644 --- a/legacy/evas/test/evas_test.c +++ b/legacy/evas/test/evas_test.c @@ -24,8 +24,8 @@ main(int argc, char **argv) d = XOpenDisplay(NULL); __evas_gl_init(d); - vis = __evas_gl_get_visual(d); - cmap = __evas_gl_get_colormap(d); + vis = __evas_gl_get_visual(d, DefaultScreen(d)); + cmap = __evas_gl_get_colormap(d, DefaultScreen(d)); win_w = 640; win_h = 480; { @@ -38,7 +38,7 @@ main(int argc, char **argv) win = XCreateWindow(d, RootWindow(d, DefaultScreen(d)), 0, 0, win_w, win_h, 0, - (__evas_gl_get_visual_info(d))->depth, + (__evas_gl_get_visual_info(d, DefaultScreen(d)))->depth, InputOutput, vis, CWColormap | CWBorderPixel | CWEventMask,