From cba4a98281dbb93436073812833af10d381f3b65 Mon Sep 17 00:00:00 2001 From: Sungbae Park Date: Mon, 20 Feb 2017 14:26:50 +0900 Subject: [PATCH] e_client : transform_core add inverse transform function Signed-off-by: Sungbae Park Change-Id: I7f202c5a4586a647a140d06efb6d64419a467a77 --- src/bin/e_client.c | 29 +++++++ src/bin/e_client.h | 3 + src/bin/e_util_transform.c | 152 ++++++++++++++++++++++++++++++++++++- src/bin/e_util_transform.h | 1 + 4 files changed, 183 insertions(+), 2 deletions(-) diff --git a/src/bin/e_client.c b/src/bin/e_client.c index 4c4fe18041..e221325b85 100644 --- a/src/bin/e_client.c +++ b/src/bin/e_client.c @@ -6421,6 +6421,7 @@ e_client_transform_core_update(E_Client *ec) // 4. apply matrix to vertices ec->transform_core.result.matrix = matrix; + ec->transform_core.result.inv_matrix = e_util_transform_matrix_inverse_get(&matrix); ec->transform_core.result.vertices = e_util_transform_rect_to_vertices(&source_rect); ec->transform_core.result.boundary.vertices = e_util_transform_rect_to_vertices(&source_rect); ec->transform_core.result.vertices = e_util_transform_matrix_multiply_rect_vertex(&matrix, @@ -6471,6 +6472,34 @@ e_client_transform_core_transform_get(E_Client *ec, int index) return (E_Util_Transform*)eina_list_nth(ec->transform_core.transform_list, index); } +E_API void +e_client_transform_core_input_transform(E_Client *ec, int x, int y, int *out_x, int *out_y) +{ + E_Util_Transform_Vertex vertex, result_vertex; + + if (!ec) return; + if (!e_client_transform_core_enable_get(ec)) return; + + e_util_transform_vertex_init(&vertex, x, y, 0.0, 1.0); + + result_vertex = e_util_transform_matrix_multiply_vertex(&ec->transform_core.result.inv_matrix, &vertex); + e_util_transform_vertex_pos_round_get(&result_vertex, out_x, out_y, NULL, NULL); +} + +E_API void +e_client_transform_core_input_inv_transform(E_Client *ec, int x, int y, int *out_x, int *out_y) +{ + E_Util_Transform_Vertex vertex, result_vertex; + + if (!ec) return; + if (!e_client_transform_core_enable_get(ec)) return; + + e_util_transform_vertex_init(&vertex, x, y, 0.0, 1.0); + + result_vertex = e_util_transform_matrix_multiply_vertex(&ec->transform_core.result.matrix, &vertex); + e_util_transform_vertex_pos_round_get(&result_vertex, out_x, out_y, NULL, NULL); +} + E_API E_Pixmap * e_client_pixmap_change(E_Client *ec, E_Pixmap *newcp) { diff --git a/src/bin/e_client.h b/src/bin/e_client.h index e7db890148..14ad3b76ae 100644 --- a/src/bin/e_client.h +++ b/src/bin/e_client.h @@ -880,6 +880,7 @@ struct E_Client { Eina_Bool enable; E_Util_Transform_Matrix matrix; + E_Util_Transform_Matrix inv_matrix; E_Util_Transform_Rect_Vertex vertices; E_Util_Transform transform; @@ -1085,6 +1086,8 @@ E_API void e_client_transform_core_remove(E_Client *ec, E_Util_Tran E_API void e_client_transform_core_update(E_Client *ec); E_API int e_client_transform_core_transform_count_get(E_Client *ec); E_API E_Util_Transform *e_client_transform_core_transform_get(E_Client *ec, int index); +E_API void e_client_transform_core_input_transform(E_Client *ec, int x, int y, int *out_x, int *out_y); +E_API void e_client_transform_core_input_inv_transform(E_Client *ec, int x, int y, int *out_x, int *out_y); E_API E_Pixmap *e_client_pixmap_change(E_Client *ec, E_Pixmap *newcp); E_API void e_client_window_role_set(E_Client *ec, const char *role); diff --git a/src/bin/e_util_transform.c b/src/bin/e_util_transform.c index 1fea0b2928..79b24c952f 100644 --- a/src/bin/e_util_transform.c +++ b/src/bin/e_util_transform.c @@ -1,5 +1,5 @@ #include "e.h" -#define E_UTIL_TRANSFORM_IS_ZERO(p) ((p) > -1e-21 && (p) < 1e-21) +#define E_UTIL_TRANSFORM_IS_ZERO(p) ((p) > -1e-6 && (p) < 1e-6) #define E_UTIL_TRANSFORM_ROUND(x) ((x) >= 0 ? (int)((x) + 0.5) : (int)((x) - 0.5)) static void _e_util_transform_value_merge(E_Util_Transform_Value *inout, E_Util_Transform_Value *input); @@ -780,7 +780,7 @@ e_util_transform_matrix_equal_check(E_Util_Transform_Matrix *matrix, { for (col = 0 ; col < 4 ; ++col) { - if (matrix->mat[row][col] != matrix2->mat[row][col]) + if (!E_UTIL_TRANSFORM_IS_ZERO(matrix->mat[row][col] - matrix2->mat[row][col])) { result = EINA_FALSE; break; @@ -791,6 +791,154 @@ e_util_transform_matrix_equal_check(E_Util_Transform_Matrix *matrix, return result; } +E_API E_Util_Transform_Matrix +e_util_transform_matrix_inverse_get(E_Util_Transform_Matrix *matrix) +{ + E_Util_Transform_Matrix result; + float det = 0.0f, inv_det = 0.0f; + int i, j; + + e_util_transform_matrix_load_identity(&result); + + if (!matrix) return result; + + + result.mat[0][0] = matrix->mat[1][1] * matrix->mat[2][2] * matrix->mat[3][3] + + matrix->mat[1][2] * matrix->mat[2][3] * matrix->mat[3][1] + + matrix->mat[1][3] * matrix->mat[2][1] * matrix->mat[3][2] + - matrix->mat[1][1] * matrix->mat[2][3] * matrix->mat[3][2] + - matrix->mat[1][2] * matrix->mat[2][1] * matrix->mat[3][3] + - matrix->mat[1][3] * matrix->mat[2][2] * matrix->mat[3][1]; + + result.mat[0][1] = matrix->mat[0][1] * matrix->mat[2][3] * matrix->mat[3][2] + + matrix->mat[0][2] * matrix->mat[2][1] * matrix->mat[3][3] + + matrix->mat[0][3] * matrix->mat[2][2] * matrix->mat[3][1] + - matrix->mat[0][1] * matrix->mat[2][2] * matrix->mat[3][3] + - matrix->mat[0][2] * matrix->mat[2][3] * matrix->mat[3][1] + - matrix->mat[0][3] * matrix->mat[2][1] * matrix->mat[3][2]; + + result.mat[0][2] = matrix->mat[0][1] * matrix->mat[1][2] * matrix->mat[3][3] + + matrix->mat[0][2] * matrix->mat[1][3] * matrix->mat[3][1] + + matrix->mat[0][3] * matrix->mat[1][1] * matrix->mat[3][2] + - matrix->mat[0][1] * matrix->mat[1][3] * matrix->mat[3][2] + - matrix->mat[0][2] * matrix->mat[1][1] * matrix->mat[3][3] + - matrix->mat[0][3] * matrix->mat[1][2] * matrix->mat[3][1]; + + result.mat[0][3] = matrix->mat[0][1] * matrix->mat[1][3] * matrix->mat[2][2] + + matrix->mat[0][2] * matrix->mat[1][1] * matrix->mat[2][3] + + matrix->mat[0][3] * matrix->mat[1][2] * matrix->mat[2][1] + - matrix->mat[0][1] * matrix->mat[1][2] * matrix->mat[2][3] + - matrix->mat[0][2] * matrix->mat[1][3] * matrix->mat[2][1] + - matrix->mat[0][3] * matrix->mat[1][1] * matrix->mat[2][2]; + + result.mat[1][0] = matrix->mat[1][0] * matrix->mat[2][3] * matrix->mat[3][2] + + matrix->mat[1][2] * matrix->mat[2][0] * matrix->mat[3][3] + + matrix->mat[1][3] * matrix->mat[2][2] * matrix->mat[3][0] + - matrix->mat[1][0] * matrix->mat[2][2] * matrix->mat[3][3] + - matrix->mat[1][2] * matrix->mat[2][3] * matrix->mat[3][0] + - matrix->mat[1][3] * matrix->mat[2][0] * matrix->mat[3][2]; + + result.mat[1][1] = matrix->mat[0][0] * matrix->mat[2][2] * matrix->mat[3][3] + + matrix->mat[0][2] * matrix->mat[2][3] * matrix->mat[3][0] + + matrix->mat[0][3] * matrix->mat[2][0] * matrix->mat[3][2] + - matrix->mat[0][0] * matrix->mat[2][3] * matrix->mat[3][2] + - matrix->mat[0][2] * matrix->mat[2][0] * matrix->mat[3][3] + - matrix->mat[0][3] * matrix->mat[2][2] * matrix->mat[3][0]; + + result.mat[1][2] = matrix->mat[0][0] * matrix->mat[1][3] * matrix->mat[3][2] + + matrix->mat[0][2] * matrix->mat[1][0] * matrix->mat[3][3] + + matrix->mat[0][3] * matrix->mat[1][2] * matrix->mat[3][0] + - matrix->mat[0][0] * matrix->mat[1][2] * matrix->mat[3][3] + - matrix->mat[0][2] * matrix->mat[1][3] * matrix->mat[3][0] + - matrix->mat[0][3] * matrix->mat[1][0] * matrix->mat[3][2]; + + result.mat[1][3] = matrix->mat[0][0] * matrix->mat[1][2] * matrix->mat[2][3] + + matrix->mat[0][2] * matrix->mat[1][3] * matrix->mat[2][0] + + matrix->mat[0][3] * matrix->mat[1][0] * matrix->mat[2][2] + - matrix->mat[0][0] * matrix->mat[1][3] * matrix->mat[2][2] + - matrix->mat[0][2] * matrix->mat[1][0] * matrix->mat[2][3] + - matrix->mat[0][3] * matrix->mat[1][2] * matrix->mat[2][0]; + + result.mat[2][0] = matrix->mat[1][0] * matrix->mat[2][1] * matrix->mat[3][3] + + matrix->mat[1][1] * matrix->mat[2][3] * matrix->mat[3][0] + + matrix->mat[1][3] * matrix->mat[2][0] * matrix->mat[3][1] + - matrix->mat[1][0] * matrix->mat[2][3] * matrix->mat[3][1] + - matrix->mat[1][1] * matrix->mat[2][0] * matrix->mat[3][3] + - matrix->mat[1][3] * matrix->mat[2][1] * matrix->mat[3][0]; + + result.mat[2][1] = matrix->mat[0][0] * matrix->mat[2][3] * matrix->mat[3][1] + + matrix->mat[0][1] * matrix->mat[2][0] * matrix->mat[3][3] + + matrix->mat[0][3] * matrix->mat[2][1] * matrix->mat[3][0] + - matrix->mat[0][0] * matrix->mat[2][1] * matrix->mat[3][3] + - matrix->mat[0][1] * matrix->mat[2][3] * matrix->mat[3][0] + - matrix->mat[0][3] * matrix->mat[2][0] * matrix->mat[3][1]; + + result.mat[2][2] = matrix->mat[0][0] * matrix->mat[1][1] * matrix->mat[3][3] + + matrix->mat[0][1] * matrix->mat[1][3] * matrix->mat[3][0] + + matrix->mat[0][3] * matrix->mat[1][0] * matrix->mat[3][1] + - matrix->mat[0][0] * matrix->mat[1][3] * matrix->mat[3][1] + - matrix->mat[0][1] * matrix->mat[1][0] * matrix->mat[3][3] + - matrix->mat[0][3] * matrix->mat[1][1] * matrix->mat[3][0]; + + result.mat[2][3] = matrix->mat[0][0] * matrix->mat[1][3] * matrix->mat[2][1] + + matrix->mat[0][1] * matrix->mat[1][0] * matrix->mat[2][3] + + matrix->mat[0][3] * matrix->mat[1][1] * matrix->mat[2][0] + - matrix->mat[0][0] * matrix->mat[1][1] * matrix->mat[2][3] + - matrix->mat[0][1] * matrix->mat[1][3] * matrix->mat[2][0] + - matrix->mat[0][3] * matrix->mat[1][0] * matrix->mat[2][1]; + + result.mat[3][0] = matrix->mat[1][0] * matrix->mat[2][2] * matrix->mat[3][1] + + matrix->mat[1][1] * matrix->mat[2][0] * matrix->mat[3][2] + + matrix->mat[1][2] * matrix->mat[2][1] * matrix->mat[3][0] + - matrix->mat[1][0] * matrix->mat[2][1] * matrix->mat[3][2] + - matrix->mat[1][1] * matrix->mat[2][2] * matrix->mat[3][0] + - matrix->mat[1][2] * matrix->mat[2][0] * matrix->mat[3][1]; + + result.mat[3][1] = matrix->mat[0][0] * matrix->mat[2][1] * matrix->mat[3][2] + + matrix->mat[0][1] * matrix->mat[2][2] * matrix->mat[3][0] + + matrix->mat[0][2] * matrix->mat[2][0] * matrix->mat[3][1] + - matrix->mat[0][0] * matrix->mat[2][2] * matrix->mat[3][1] + - matrix->mat[0][1] * matrix->mat[2][0] * matrix->mat[3][2] + - matrix->mat[0][2] * matrix->mat[2][1] * matrix->mat[3][0]; + + result.mat[3][2] = matrix->mat[0][0] * matrix->mat[1][2] * matrix->mat[3][1] + + matrix->mat[0][1] * matrix->mat[1][0] * matrix->mat[3][2] + + matrix->mat[0][2] * matrix->mat[1][1] * matrix->mat[3][0] + - matrix->mat[0][0] * matrix->mat[1][1] * matrix->mat[3][2] + - matrix->mat[0][1] * matrix->mat[1][2] * matrix->mat[3][0] + - matrix->mat[0][2] * matrix->mat[1][0] * matrix->mat[3][1]; + + result.mat[3][3] = matrix->mat[0][0] * matrix->mat[1][1] * matrix->mat[2][2] + + matrix->mat[0][1] * matrix->mat[1][2] * matrix->mat[2][0] + + matrix->mat[0][2] * matrix->mat[1][0] * matrix->mat[2][1] + - matrix->mat[0][0] * matrix->mat[1][2] * matrix->mat[2][1] + - matrix->mat[0][1] * matrix->mat[1][0] * matrix->mat[2][2] + - matrix->mat[0][2] * matrix->mat[1][1] * matrix->mat[2][0]; + + det = matrix->mat[0][0] * result.mat[0][0] + + matrix->mat[0][1] * result.mat[1][0] + + matrix->mat[0][2] * result.mat[2][0] + + matrix->mat[0][3] * result.mat[3][0]; + + + if (E_UTIL_TRANSFORM_IS_ZERO(det)) + { + e_util_transform_matrix_load_identity(&result); + } + else + { + inv_det = 1.0f / det; + + for (i = 0 ; i < 4 ; ++i) + { + for (j = 0 ; j < 4 ; ++j) + result.mat[i][j] *= inv_det; + } + } + + return result; +} + static void _e_util_transform_value_merge(E_Util_Transform_Value *inout, E_Util_Transform_Value *input) { diff --git a/src/bin/e_util_transform.h b/src/bin/e_util_transform.h index c96a01ea38..c4912fadb8 100644 --- a/src/bin/e_util_transform.h +++ b/src/bin/e_util_transform.h @@ -132,6 +132,7 @@ E_API E_Util_Transform_Rect_Vertex e_util_transform_matrix_multiply_rect_vertex( E_Util_Transform_Rect_Vertex *vertices); E_API Eina_Bool e_util_transform_matrix_equal_check(E_Util_Transform_Matrix *matrix, E_Util_Transform_Matrix *matrix2); +E_API E_Util_Transform_Matrix e_util_transform_matrix_inverse_get(E_Util_Transform_Matrix *matrix); // will delete function E_API void e_util_transform_source_to_target(E_Util_Transform *transform, -- 2.34.1