pepper: Conversion between global and view local space
authorTaekyun Kim <tkq.kim@samsung.com>
Wed, 26 Aug 2015 05:41:09 +0000 (14:41 +0900)
committer김태균 <tkq.kim@samsung.com>
Wed, 26 Aug 2015 07:27:59 +0000 (16:27 +0900)
Change-Id: I7a8e13b71b745218cbac9f051f157290f71c03b7

src/lib/pepper/pepper-internal.h
src/lib/pepper/view.c

index 2d69158..24c0e32 100644 (file)
@@ -321,6 +321,7 @@ struct pepper_view
     int                         w, h;
     pepper_mat4_t               transform;
     pepper_mat4_t               global_transform;
+    pepper_mat4_t               global_transform_inverse;
 
     pixman_region32_t           bounding_region;
     pixman_region32_t           opaque_region;
@@ -349,6 +350,16 @@ pepper_view_update(pepper_view_t *view);
 void
 pepper_view_surface_damage(pepper_view_t *view);
 
+void
+pepper_view_get_local_coordinate(pepper_view_t *view,
+                                 double global_x, double global_y,
+                                 double *local_x, double *local_y);
+
+void
+pepper_view_get_global_coordinate(pepper_view_t *view,
+                                  double local_x, double local_y,
+                                  double *global_x, double *global_y);
+
 struct pepper_plane
 {
     pepper_object_t     base;
index 23bea67..3fcbca9 100644 (file)
@@ -72,6 +72,38 @@ pepper_view_surface_damage(pepper_view_t *view)
     }
 }
 
+void
+pepper_view_get_local_coordinate(pepper_view_t *view,
+                                 double global_x, double global_y,
+                                 double *local_x, double *local_y)
+{
+    pepper_vec4_t pos = { global_x, global_y, 0.0, 1.0 };
+
+    pepper_view_update(view);
+    pepper_mat4_transform_vec4(&view->global_transform_inverse, &pos);
+
+    PEPPER_ASSERT(pos.w >= 1e-6);
+
+    *local_x = pos.x / pos.w;
+    *local_y = pos.y / pos.w;
+}
+
+void
+pepper_view_get_global_coordinate(pepper_view_t *view,
+                                  double local_x, double local_y,
+                                  double *global_x, double *global_y)
+{
+    pepper_vec4_t pos = { local_x, local_y, 0.0, 1.0 };
+
+    pepper_view_update(view);
+    pepper_mat4_transform_vec4(&view->global_transform, &pos);
+
+    PEPPER_ASSERT(pos.w >= 1e-6);
+
+    *global_x = pos.x / pos.w;
+    *global_y = pos.y / pos.w;
+}
+
 static void
 view_handle_surface_destroy(pepper_event_listener_t *listener,
                             pepper_object_t *object, uint32_t id, void *info, void *data)
@@ -177,6 +209,8 @@ view_update_geometry(pepper_view_t *view)
                              &view->parent->global_transform, &view->global_transform);
     }
 
+    pepper_mat4_inverse(&view->global_transform_inverse, &view->global_transform);
+
     /* Bounding region. */
     pixman_region32_init_rect(&view->bounding_region, 0, 0, view->w, view->h);
     pepper_transform_pixman_region(&view->bounding_region, &view->global_transform);