From fa6a067737817c558735a943bff592b201a2d496 Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Sun, 9 May 2010 05:15:20 +0000 Subject: [PATCH] gl engine now does rotates (0, 90, 180, 270), like software engines SVN revision: 48704 --- .../engines/gl_common/evas_gl_common.h | 4 +- .../engines/gl_common/evas_gl_context.c | 95 +++++++++++++++---- .../src/modules/engines/gl_x11/evas_engine.c | 21 ++-- .../src/modules/engines/gl_x11/evas_engine.h | 3 +- .../src/modules/engines/gl_x11/evas_x_main.c | 8 +- 5 files changed, 101 insertions(+), 30 deletions(-) diff --git a/legacy/evas/src/modules/engines/gl_common/evas_gl_common.h b/legacy/evas/src/modules/engines/gl_common/evas_gl_common.h index f268d94536..ce4acf1d36 100644 --- a/legacy/evas/src/modules/engines/gl_common/evas_gl_common.h +++ b/legacy/evas/src/modules/engines/gl_common/evas_gl_common.h @@ -113,12 +113,14 @@ struct _Evas_GL_Shared } shader; int references; int w, h; + int rot; }; struct _Evas_GL_Context { int references; int w, h; + int rot; RGBA_Draw_Context *dc; Evas_GL_Shared *shared; @@ -284,7 +286,7 @@ void glerr(int err, const char *file, const char *func, int line, const char *op Evas_GL_Context *evas_gl_common_context_new(void); void evas_gl_common_context_free(Evas_GL_Context *gc); void evas_gl_common_context_use(Evas_GL_Context *gc); -void evas_gl_common_context_resize(Evas_GL_Context *gc, int w, int h); +void evas_gl_common_context_resize(Evas_GL_Context *gc, int w, int h, int rot); void evas_gl_common_context_target_surface_set(Evas_GL_Context *gc, Evas_GL_Image *surface); void evas_gl_common_context_line_push(Evas_GL_Context *gc, diff --git a/legacy/evas/src/modules/engines/gl_common/evas_gl_context.c b/legacy/evas/src/modules/engines/gl_common/evas_gl_context.c index 9cf420deab..14a1333610 100644 --- a/legacy/evas/src/modules/engines/gl_common/evas_gl_context.c +++ b/legacy/evas/src/modules/engines/gl_common/evas_gl_context.c @@ -80,29 +80,83 @@ matrix_ident(GLfloat *m) { memset(m, 0, 16 * sizeof(GLfloat)); m[0] = m[5] = m[10] = m[15] = 1.0; + //------------------------ + // 1 0 0 0 + // 0 1 0 0 + // 0 0 1 0 + // 0 0 0 1 } static void matrix_ortho(GLfloat *m, GLfloat l, GLfloat r, GLfloat t, GLfloat b, - GLfloat near, GLfloat far) + GLfloat near, GLfloat far, + int rot, int w, int h) { - m[0] = 2.0 / (r - l); - m[1] = m[2] = m[3] = 0.0; + GLfloat rotf; + GLfloat cosv, sinv; + GLfloat tx, ty; +// rot = 180; + //------------------------ + m[0] = 2.0 / (r - l); + m[1] = 0.0; + m[2] = 0.0; + m[3] = 0.0; + + //------------------------ m[4] = 0.0; m[5] = 2.0 / (t - b); - m[6] = m[7] = 0.0; + m[6] = 0.0; + m[7] = 0.0; - m[8] = m[9] = 0.0; + //------------------------ + m[8] = 0.0; + m[9] = 0.0; m[10] = -(2.0 / (far - near)); m[11] = 0.0; - m[12] = -((r + l)/(r - l)); - m[13] = -((t + b)/(t - b)); - m[14] = -((near + far)/(far - near)); + //------------------------ + m[12] = -((r + l) / (r - l)); + m[13] = -((t + b) / (t - b)); + m[14] = -((near + far) / (far - near)); m[15] = 1.0; + + // rot + rotf = (((rot / 90) & 0x3) * M_PI) / 2.0; + + tx = 0.0; + ty = 0.0; + if (rot == 90) + { + tx = -(w * 1.0); + ty = -(h * 0.0); + } + if (rot == 180) + { + tx = -(w * 1.0); + ty = -(h * 1.0); + } + if (rot == 270) + { + tx = -(w * 0.0); + ty = -(h * 1.0); + } + + cosv = cos(rotf); + sinv = sin(rotf); + + m[0] = (2.0 / (r - l)) * ( cosv); + m[1] = (2.0 / (r - l)) * ( sinv); + + m[4] = (2.0 / (t - b)) * (-sinv); + m[5] = (2.0 / (t - b)) * ( cosv); + + m[12] += (m[0] * tx) + (m[4] * ty); + m[13] += (m[1] * tx) + (m[5] * ty); + m[14] += (m[2] * tx) + (m[6] * ty); + m[15] += (m[3] * tx) + (m[7] * ty); } static int @@ -119,7 +173,7 @@ _evas_gl_common_version_check() * GL_VERSION is used to get the version of the connection */ - version = glGetString(GL_VERSION); + version = (char *)glGetString(GL_VERSION); /* * OpengL ES @@ -197,35 +251,41 @@ static void _evas_gl_common_viewport_set(Evas_GL_Context *gc) { GLfloat proj[16]; - int w = 1, h = 1, m = 1; + int w = 1, h = 1, m = 1, rot = 1; if ((gc->shader.surface == gc->def_surface) || (!gc->shader.surface)) { w = gc->w; h = gc->h; + rot = gc->rot; } else { w = gc->shader.surface->w; h = gc->shader.surface->h; + rot = 0; m = -1; } if ((!gc->change.size) || - ((gc->shared->w == w) && (gc->shared->h == h))) + ((gc->shared->w == w) && (gc->shared->h == h) && (gc->shared->rot == rot))) return; gc->shared->w = w; gc->shared->h = h; + gc->shared->rot = rot; gc->change.size = 0; - - glViewport(0, 0, w, h); + + if ((rot == 0) || (rot == 180)) + glViewport(0, 0, w, h); + else + glViewport(0, 0, h, w); GLERR(__FUNCTION__, __FILE__, __LINE__, ""); matrix_ident(proj); - if (m == 1) matrix_ortho(proj, 0, w, 0, h, -1.0, 1.0); - else matrix_ortho(proj, 0, w, h, 0, -1.0, 1.0); + if (m == 1) matrix_ortho(proj, 0, w, 0, h, -1.0, 1.0, rot, w, h); + else matrix_ortho(proj, 0, w, h, 0, -1.0, 1.0, rot, w, h); glUseProgram(gc->shared->shader.rect.prog); GLERR(__FUNCTION__, __FILE__, __LINE__, ""); @@ -540,10 +600,11 @@ evas_gl_common_context_use(Evas_GL_Context *gc) } void -evas_gl_common_context_resize(Evas_GL_Context *gc, int w, int h) +evas_gl_common_context_resize(Evas_GL_Context *gc, int w, int h, int rot) { - if ((gc->w == w) && (gc->h == h)) return; + if ((gc->w == w) && (gc->h == h) && (gc->rot == rot)) return; gc->change.size = 1; + gc->rot = rot; gc->w = w; gc->h = h; if (_evas_gl_common_context == gc) _evas_gl_common_viewport_set(gc); diff --git a/legacy/evas/src/modules/engines/gl_x11/evas_engine.c b/legacy/evas/src/modules/engines/gl_x11/evas_engine.c index ba649373fd..b42c8d1217 100644 --- a/legacy/evas/src/modules/engines/gl_x11/evas_engine.c +++ b/legacy/evas/src/modules/engines/gl_x11/evas_engine.c @@ -220,14 +220,15 @@ eng_setup(Evas *e, void *in) e->engine.data.output = re; re->win = eng_window_new(info->info.display, info->info.drawable, - 0 /* FIXME: screen 0 assumption */, + info->info.screen, info->info.visual, info->info.colormap, info->info.depth, e->output.w, e->output.h, info->indirect, - info->info.destination_alpha); + info->info.destination_alpha, + info->info.rotation); if (!re->win) { free(re); @@ -308,23 +309,25 @@ eng_setup(Evas *e, void *in) re = e->engine.data.output; if ((info->info.display != re->win->disp) || (info->info.drawable != re->win->win) || - (0 != re->win->screen) || /* FIXME: screen 0 assumption */ + (info->info.screen != re->win->screen) || (info->info.visual != re->win->visual) || (info->info.colormap != re->win->colormap) || (info->info.depth != re->win->depth) || - (info->info.destination_alpha != re->win->alpha)) + (info->info.destination_alpha != re->win->alpha) || + (info->info.rotation != re->win->rot)) { eng_window_free(re->win); re->win = eng_window_new(info->info.display, info->info.drawable, - 0,/* FIXME: screen 0 assumption */ + info->info.screen, info->info.visual, info->info.colormap, info->info.depth, e->output.w, e->output.h, info->indirect, - info->info.destination_alpha); + info->info.destination_alpha, + info->info.rotation); } else if ((re->win->w != e->output.w) || (re->win->h != e->output.h)) @@ -332,7 +335,7 @@ eng_setup(Evas *e, void *in) re->win->w = e->output.w; re->win->h = e->output.h; eng_window_use(re->win); - evas_gl_common_context_resize(re->win->gl_context, re->win->w, re->win->h); + evas_gl_common_context_resize(re->win->gl_context, re->win->w, re->win->h, re->win->rot); } } @@ -379,7 +382,7 @@ eng_output_resize(void *data, int w, int h) re->win->w = w; re->win->h = h; eng_window_use(re->win); - evas_gl_common_context_resize(re->win->gl_context, w, h); + evas_gl_common_context_resize(re->win->gl_context, w, h, re->win->rot); } static void @@ -396,7 +399,7 @@ eng_output_redraws_rect_add(void *data, int x, int y, int w, int h) Render_Engine *re; re = (Render_Engine *)data; - evas_gl_common_context_resize(re->win->gl_context, re->win->w, re->win->h); + evas_gl_common_context_resize(re->win->gl_context, re->win->w, re->win->h, re->win->rot); /* smple bounding box */ RECTS_CLIP_TO_RECT(x, y, w, h, 0, 0, re->win->w, re->win->h); if ((w <= 0) || (h <= 0)) return; diff --git a/legacy/evas/src/modules/engines/gl_x11/evas_engine.h b/legacy/evas/src/modules/engines/gl_x11/evas_engine.h index 0efb633c18..2d0a3f6d86 100644 --- a/legacy/evas/src/modules/engines/gl_x11/evas_engine.h +++ b/legacy/evas/src/modules/engines/gl_x11/evas_engine.h @@ -82,6 +82,7 @@ struct _Evas_GL_X11_Window Colormap colormap; int depth; int alpha; + int rot; Evas_GL_Context *gl_context; struct { int redraw : 1; @@ -114,7 +115,7 @@ struct _Evas_GL_X11_Window Evas_GL_X11_Window *eng_window_new(Display *disp, Window win, int screen, Visual *vis, Colormap cmap, int depth, int w, int h, int indirect, - int alpha); + int alpha, int rot); void eng_window_free(Evas_GL_X11_Window *gw); void eng_window_use(Evas_GL_X11_Window *gw); Visual *eng_best_visual_get(Evas_Engine_Info_GL_X11 *einfo); diff --git a/legacy/evas/src/modules/engines/gl_x11/evas_x_main.c b/legacy/evas/src/modules/engines/gl_x11/evas_x_main.c index b497e0e10a..16e75b69d0 100644 --- a/legacy/evas/src/modules/engines/gl_x11/evas_x_main.c +++ b/legacy/evas/src/modules/engines/gl_x11/evas_x_main.c @@ -32,7 +32,8 @@ eng_window_new(Display *disp, int w, int h, int indirect, - int alpha) + int alpha, + int rot) { Evas_GL_X11_Window *gw; int context_attrs[3]; @@ -53,6 +54,9 @@ eng_window_new(Display *disp, gw->colormap = cmap; gw->depth = depth; gw->alpha = alpha; + gw->w = w; + gw->h = h; + gw->rot = rot; vi_use = _evas_gl_x11_vi; if (alpha) @@ -382,7 +386,7 @@ eng_window_new(Display *disp, return NULL; } evas_gl_common_context_use(gw->gl_context); - evas_gl_common_context_resize(gw->gl_context, w, h); + evas_gl_common_context_resize(gw->gl_context, w, h, rot); win_count++; return gw; }