VIGS/qt5: support rotation 07/25107/2
authorStanislav Vorobiov <s.vorobiov@samsung.com>
Tue, 29 Jul 2014 14:01:35 +0000 (18:01 +0400)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Wed, 30 Jul 2014 05:10:25 +0000 (22:10 -0700)
Rotation is supported via ortho
multiplication

Change-Id: I1f569e259a61b200adb707104b066a4f9fa69213
Signed-off-by: Stanislav Vorobiov <s.vorobiov@samsung.com>
hw/vigs/vigs_gl_backend.c
tizen/src/ui/displaywidget.cpp

index eda75cd316512746e779ce052ca715b474d692b9..8b527b9975d07325fd01c9b883de9a3d32206888 100644 (file)
 #include "vigs_utils.h"
 #include "vigs_ref.h"
 #include "winsys_gl.h"
+#include <math.h>
 
 extern uint32_t qt5_window_width;
 extern uint32_t qt5_window_height;
+extern int qt5_window_angle;
 
 struct vigs_gl_surface;
 
@@ -99,6 +101,13 @@ struct vigs_gl_surface
      * Ortho matrix for this surface.
      */
     GLfloat ortho[16];
+
+    /*
+     * Rotation angle and corresponding ortho,
+     * for display.
+     */
+    int dpy_angle;
+    GLfloat dpy_ortho[16];
 };
 
 static __inline struct vigs_winsys_gl_surface
@@ -657,6 +666,28 @@ static void vigs_gl_create_ortho(GLfloat left, GLfloat right,
     ortho[15] = 1.0f;
 }
 
+static void vigs_gl_rotate_ortho(const GLfloat ortho[16],
+                                 GLfloat angle,
+                                 GLfloat res[16])
+{
+    GLfloat rot[4][4] = {
+        { cos(angle), sin(angle), 0, 0 },
+        { -sin(angle), cos(angle), 0, 0 },
+        { 0, 0, 1, 0 },
+        { 0, 0, 0, 1 }
+    };
+    int i, j, k;
+
+    for (i = 0; i < 4; ++i) {
+        for (j = 0; j < 4; ++j) {
+            res[i * 4 + j] = 0.0f;
+            for (k = 0; k < 4; ++k) {
+                res[i * 4 + j] += ortho[i * 4 + k] * rot[k][j];
+            }
+        }
+    }
+}
+
 static void vigs_gl_translate_color(vigsp_color color,
                                     vigsp_surface_format format,
                                     GLfloat res[4])
@@ -1399,6 +1430,7 @@ static bool vigs_gl_backend_composite(struct vigs_surface *surface,
     GLfloat *tex_coords;
     const struct vigs_plane *sorted_planes[VIGS_MAX_PLANES];
     bool scale;
+    GLfloat *ortho;
 
     VIGS_LOG_TRACE("enter");
 
@@ -1439,6 +1471,18 @@ static bool vigs_gl_backend_composite(struct vigs_surface *surface,
         }
     }
 
+    if (qt5_window_angle == 0) {
+        ortho = gl_root_sfc->ortho;
+    } else {
+        if (gl_root_sfc->dpy_angle != qt5_window_angle) {
+            vigs_gl_rotate_ortho(gl_root_sfc->ortho,
+                                 (float)(360.0f - qt5_window_angle) * M_PI / 180.0f,
+                                 gl_root_sfc->dpy_ortho);
+            gl_root_sfc->dpy_angle = qt5_window_angle;
+        }
+        ortho = gl_root_sfc->dpy_ortho;
+    }
+
     scale = (qt5_window_width != ws_root_sfc->base.base.width) ||
             (qt5_window_height != ws_root_sfc->base.base.height);
 
@@ -1451,7 +1495,7 @@ static bool vigs_gl_backend_composite(struct vigs_surface *surface,
 
         gl_backend->UseProgram(gl_backend->dpy_scale_prog_id);
         gl_backend->UniformMatrix4fv(gl_backend->dpy_scale_prog_proj_loc, 1, GL_FALSE,
-                                     gl_root_sfc->ortho);
+                                     ortho);
 
         texSize[0] = ws_root_sfc->base.base.width;
         texSize[1] = ws_root_sfc->base.base.height;
@@ -1460,7 +1504,7 @@ static bool vigs_gl_backend_composite(struct vigs_surface *surface,
     } else {
         gl_backend->UseProgram(gl_backend->dpy_tex_prog_id);
         gl_backend->UniformMatrix4fv(gl_backend->dpy_tex_prog_proj_loc, 1, GL_FALSE,
-                                     gl_root_sfc->ortho);
+                                     ortho);
     }
 
     gl_backend->BindTexture(GL_TEXTURE_2D, ws_root_sfc->tex);
index 9d469c44fd64501003ef4ca7a02e288fd86d7661..953dd52897bc574cb594fe2e926172b3f49b5530 100644 (file)
@@ -10,6 +10,7 @@ void do_mouse_event(int button_type, int event_type,
 
 uint32_t qt5_window_width = 0;
 uint32_t qt5_window_height = 0;
+int qt5_window_angle = 0;
 
 DisplayWidget::DisplayWidget(QSize resolution, QGLContext *context, QWidget *parent) :
     QGLWidget(context, parent)
@@ -39,6 +40,8 @@ void DisplayWidget::rotate(int angle)
 
     rotateAngle = angle;
 
+    qt5_window_angle = angle;
+
     /* adjustSize() doesn't work */
     resize(0, 0);