From cf5d5718e25e8eaca0e5a61d9392df23ed23d69c Mon Sep 17 00:00:00 2001 From: doursse Date: Thu, 26 Jun 2008 08:29:25 +0000 Subject: [PATCH] put initialisation of glew in the engine, update the engine so that it uses the cache system SVN revision: 34912 --- .../engines/gl_glew/Evas_Engine_GL_Glew.h | 2 +- .../src/modules/engines/gl_glew/evas_engine.c | 63 ++++++++---- .../src/modules/engines/gl_glew/evas_engine.h | 24 +++-- .../modules/engines/gl_glew/evas_glew_main.c | 99 +++++++++++++------ 4 files changed, 132 insertions(+), 56 deletions(-) diff --git a/legacy/evas/src/modules/engines/gl_glew/Evas_Engine_GL_Glew.h b/legacy/evas/src/modules/engines/gl_glew/Evas_Engine_GL_Glew.h index 29308092fc..f583c89f36 100644 --- a/legacy/evas/src/modules/engines/gl_glew/Evas_Engine_GL_Glew.h +++ b/legacy/evas/src/modules/engines/gl_glew/Evas_Engine_GL_Glew.h @@ -1,6 +1,7 @@ #ifndef __EVAS_ENGINE_GL_GLEW_H__ #define __EVAS_ENGINE_GL_GLEW_H__ + #include @@ -14,7 +15,6 @@ struct _Evas_Engine_Info_GL_Glew /* engine specific data & parameters it needs to set up */ struct { - HDC dc; HWND window; int depth; } info; diff --git a/legacy/evas/src/modules/engines/gl_glew/evas_engine.c b/legacy/evas/src/modules/engines/gl_glew/evas_engine.c index f640cd3b90..33f790e885 100644 --- a/legacy/evas/src/modules/engines/gl_glew/evas_engine.c +++ b/legacy/evas/src/modules/engines/gl_glew/evas_engine.c @@ -9,6 +9,9 @@ typedef struct _Render_Engine Render_Engine; struct _Render_Engine { + HWND win; + HDC dc; + HGLRC context; Evas_GL_Glew_Window *window; int end; }; @@ -48,9 +51,18 @@ eng_setup(Evas *e, void *in) re = calloc(1, sizeof(Render_Engine)); if (!re) return; + if (!evas_glew_init(info->info.window, &re->dc, &re->context)) + { + free(re); + e->engine.data.output = NULL; + return; + } + + re->win = info->info.window; e->engine.data.output = re; - re->window = eng_window_new(info->info.dc, - info->info.window, + re->window = eng_window_new(info->info.window, + re->dc, + re->context, info->info.depth, e->output.w, e->output.h); @@ -77,10 +89,20 @@ eng_setup(Evas *e, void *in) } else { + + if (!evas_glew_init(info->info.window, &re->dc, &re->context)) + { + free(re); + e->engine.data.output = NULL; + return; + } + + re->win = info->info.window; re = e->engine.data.output; eng_window_free(re->window); - re->window = eng_window_new(info->info.dc, - info->info.window, + re->window = eng_window_new(info->info.window, + re->dc, + re->context, info->info.depth, e->output.w, e->output.h); @@ -99,6 +121,7 @@ eng_output_free(void *data) re = (Render_Engine *)data; eng_window_free(re->window); + evas_glew_shutdown(re->win, re->dc, re->context); free(re); evas_common_font_shutdown(); @@ -241,7 +264,7 @@ eng_output_flush(void *data) eng_window_use(re->window); #ifdef SLOW_GL_COPY_RECT - SwapBuffers(re->window->dc); + SwapBuffers(re->dc); #else /* SLOW AS ALL HELL */ evas_gl_common_swap_rect(re->window->gl_context, @@ -499,13 +522,13 @@ eng_image_alpha_set(void *data, void *image, int has_alpha) im = image; /* FIXME: can move to gl_common */ if (im->cs.space != EVAS_COLORSPACE_ARGB8888) return im; - if ((has_alpha) && im->im->cache_entry.flags.alpha) return image; + if ((has_alpha) && (im->im->cache_entry.flags.alpha)) return image; else if ((!has_alpha) && (!im->im->cache_entry.flags.alpha)) return image; if (im->references > 1) { Evas_GL_Image *im_new; - im_new = evas_gl_common_image_new_from_copied_data(im->gc, im->im->image->w, im->im->image->h, im->im->image->data, + im_new = evas_gl_common_image_new_from_copied_data(im->gc, im->im->cache_entry.w, im->im->cache_entry.h, im->im->image.data, eng_image_alpha_get(data, image), eng_image_colorspace_get(data, image)); if (!im_new) return im; @@ -569,7 +592,7 @@ eng_image_colorspace_set(void *data, void *image, int cspace) im = image; /* FIXME: can move to gl_common */ if (im->cs.space == cspace) return; - evas_cache_image_colorspace(&im->im.cache_entry, cspace); + evas_cache_image_colorspace(&im->im->cache_entry, cspace); switch (cspace) { case EVAS_COLORSPACE_ARGB8888: @@ -588,7 +611,7 @@ eng_image_colorspace_set(void *data, void *image, int cspace) { if (!im->cs.no_free) free(im->cs.data); } - im->cs.data = calloc(1, im->im->image->h * sizeof(unsigned char *) * 2); + im->cs.data = calloc(1, im->im->cache_entry.h * sizeof(unsigned char *) * 2); im->cs.no_free = 0; break; default: @@ -615,8 +638,6 @@ eng_image_load(void *data, const char *file, const char *key, int *error, Evas_I Render_Engine *re; re = (Render_Engine *)data; - if (!re) - printf ("MERDE2\n"); *error = 0; eng_window_use(re->window); return evas_gl_common_image_load(re->window->gl_context, file, key, lo); @@ -665,8 +686,9 @@ eng_image_size_get(void *data, void *image, int *w, int *h) *h = 0; return; } - if (w) *w = ((Evas_GL_Image *)image)->im->image->w; - if (h) *h = ((Evas_GL_Image *)image)->im->image->h; + if (w) *w = ((Evas_GL_Image *)image)->im->cache_entry.w; + if (h) *h = ((Evas_GL_Image *)image)->im->cache_entry.h; + } static void * @@ -682,7 +704,8 @@ eng_image_size_set(void *data, void *image, int w, int h) if ((eng_image_colorspace_get(data, image) == EVAS_COLORSPACE_YCBCR422P601_PL) || (eng_image_colorspace_get(data, image) == EVAS_COLORSPACE_YCBCR422P709_PL)) w &= ~0x1; - if ((im_old) && (im_old->im->image->w == w) && (im_old->im->image->h == h)) + if ((im_old) && (im_old->im->cache_entry.w == w) && (im_old->im->cache_entry.h == h)) + return image; if (im_old) { @@ -729,7 +752,7 @@ eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data) } im = image; eng_window_use(re->window); - evas_common_load_image_data_from_file(im->im); + evas_cache_image_load_data(&im->im->cache_entry); switch (im->cs.space) { case EVAS_COLORSPACE_ARGB8888: @@ -739,7 +762,7 @@ eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data) { Evas_GL_Image *im_new; - im_new = evas_gl_common_image_new_from_copied_data(im->gc, im->im->image->w, im->im->image->h, im->im->image->data, + im_new = evas_gl_common_image_new_from_copied_data(im->gc, im->im->cache_entry.w, im->im->cache_entry.h, im->im->image.data, eng_image_alpha_get(data, image), eng_image_colorspace_get(data, image)); if (!im_new) @@ -753,7 +776,7 @@ eng_image_data_get(void *data, void *image, int to_write, DATA32 **image_data) else evas_gl_common_image_dirty(im); } - *image_data = im->im->image->data; + *image_data = im->im->image.data; break; case EVAS_COLORSPACE_YCBCR422P601_PL: case EVAS_COLORSPACE_YCBCR422P709_PL: @@ -779,12 +802,12 @@ eng_image_data_put(void *data, void *image, DATA32 *image_data) switch (im->cs.space) { case EVAS_COLORSPACE_ARGB8888: - if (image_data != im->im->image->data) + if (image_data != im->im->image.data) { int w, h; - w = im->im->image->w; - h = im->im->image->h; + w = im->im->cache_entry.w; + h = im->im->cache_entry.h; im2 = eng_image_new_from_data(data, w, h, image_data, eng_image_alpha_get(data, image), eng_image_colorspace_get(data, image)); diff --git a/legacy/evas/src/modules/engines/gl_glew/evas_engine.h b/legacy/evas/src/modules/engines/gl_glew/evas_engine.h index 8e25f94c18..8df1782dfb 100644 --- a/legacy/evas/src/modules/engines/gl_glew/evas_engine.h +++ b/legacy/evas/src/modules/engines/gl_glew/evas_engine.h @@ -10,22 +10,32 @@ typedef struct _Evas_GL_Glew_Window Evas_GL_Glew_Window; struct _Evas_GL_Glew_Window { - HDC dc; HWND window; + HDC dc; + HGLRC context; int width; int height; int depth; - HGLRC context; Evas_GL_Context *gl_context; struct { - int redraw : 1; - int drew : 1; - int x1, y1, x2, y2; + int x1; + int y1; + int x2; + int y2; + int redraw : 1; + int drew : 1; } draw; }; -Evas_GL_Glew_Window *eng_window_new(HDC dc, - HWND window, +int evas_glew_init(HWND window, HDC *dc, HGLRC *context); + +void evas_glew_shutdown(HWND window, + HDC dc, + HGLRC context); + +Evas_GL_Glew_Window *eng_window_new(HWND window, + HDC dc, + HGLRC context, int depth, int width, int height); diff --git a/legacy/evas/src/modules/engines/gl_glew/evas_glew_main.c b/legacy/evas/src/modules/engines/gl_glew/evas_glew_main.c index 990d68c152..1981719d3f 100644 --- a/legacy/evas/src/modules/engines/gl_glew/evas_glew_main.c +++ b/legacy/evas/src/modules/engines/gl_glew/evas_glew_main.c @@ -5,47 +5,91 @@ static Evas_GL_Glew_Window *_evas_gl_glew_window = NULL; -static HGLRC context = NULL; -static int glew_is_init = 0; +int +evas_glew_init(HWND window, HDC *dc, HGLRC *context) +{ + PIXELFORMATDESCRIPTOR pfd; + int format; + + *dc = GetDC(window); + if (!*dc) + goto no_dc; + + ZeroMemory(&pfd, sizeof (pfd)); + pfd.nSize = sizeof (pfd); + pfd.nVersion = 1; + pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; + pfd.iPixelType = PFD_TYPE_RGBA; + pfd.cColorBits = 24; + pfd.cDepthBits = 32; + pfd.iLayerType = PFD_MAIN_PLANE; + + format = ChoosePixelFormat(*dc, &pfd); + if (!format) + goto no_format; + + SetPixelFormat(*dc, format, &pfd); + + if (pfd.iPixelType != PFD_TYPE_RGBA) + goto no_format; + + *context = wglCreateContext(*dc); + if (!*context) + goto no_format; + + wglMakeCurrent(*dc, *context); + + if (glewInit() != GLEW_OK) + goto glew_init_failed; + + if (GLEW_VERSION_2_0) + { + printf ("2.0\n"); + } + + return 1; + + glew_init_failed: + wglMakeCurrent(NULL, NULL); + wglDeleteContext(*context); + no_format: + ReleaseDC(window, *dc); + no_dc: + + return 0; +} + +void +evas_glew_shutdown(HWND window, + HDC dc, + HGLRC context) +{ + wglMakeCurrent(NULL, NULL); + wglDeleteContext(context); + ReleaseDC(window, dc); +} Evas_GL_Glew_Window * -eng_window_new(HDC dc, - HWND window, - int depth, - int width, - int height) +eng_window_new(HWND window, + HDC dc, + HGLRC context, + int depth, + int width, + int height) { Evas_GL_Glew_Window *gw; gw = calloc(1, sizeof(Evas_GL_Glew_Window)); if (!gw) return NULL; - gw->dc = dc; gw->window = window; + gw->dc = dc; + gw->context = context; gw->depth = depth; - if (!context) - context = wglCreateContext(dc); - if (!context) - { - free(gw); - return NULL; - } - gw->context = context; - wglMakeCurrent(dc, context); - if (!glew_is_init) - if (glewInit() != GLEW_OK) - { - wglMakeCurrent(NULL, NULL); - wglDeleteContext(context); - free(gw); - return NULL; - } gw->gl_context = evas_gl_common_context_new(); if (!gw->gl_context) { - wglMakeCurrent(NULL, NULL); - wglDeleteContext(context); free(gw); return NULL; } @@ -59,7 +103,6 @@ eng_window_free(Evas_GL_Glew_Window *gw) { if (gw == _evas_gl_glew_window) _evas_gl_glew_window = NULL; evas_gl_common_context_free(gw->gl_context); - /* wglDeleteContext(gw->context); */ free(gw); }