servo: Merge #11537 - compositing: Don't translate points to layer space when using WebRender (from pcwalton:webrender-remove-layer-space-translation); r=glennw
authorPatrick Walton <pcwalton@mimiga.net>
Thu, 02 Jun 2016 20:50:55 -0500
changeset 338994 bf725e88c2e0afbc772b6fc089ac34d28120750c
parent 338993 a04ac887b5958366962198d760046a7981037d59
child 338995 69a15042eaa254065baf6c96b49b422218a974f2
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersglennw
servo: Merge #11537 - compositing: Don't translate points to layer space when using WebRender (from pcwalton:webrender-remove-layer-space-translation); r=glennw This makes mouse events take the same code path, regardless of whether WebRender is in use or not. This approach enables accurate display-list-based hit testing when WebRender is in use. Closes #11108. r? @glennw Source-Repo: https://github.com/servo/servo Source-Revision: 77e6ea95873c1fc06ea6e19fa20c727b9ca808a9
servo/components/compositing/compositor.rs
--- a/servo/components/compositing/compositor.rs
+++ b/servo/components/compositing/compositor.rs
@@ -1382,41 +1382,37 @@ impl<Window: WindowMethods> IOCompositor
         }
 
         let point = match mouse_window_event {
             MouseWindowEvent::Click(_, p) => p,
             MouseWindowEvent::MouseDown(_, p) => p,
             MouseWindowEvent::MouseUp(_, p) => p,
         };
 
-        if let Some(ref webrender_api) = self.webrender_api {
+        if self.webrender_api.is_some() {
             let root_pipeline_id = match self.get_root_pipeline_id() {
                 Some(root_pipeline_id) => root_pipeline_id,
                 None => return,
             };
-            if self.pipeline(root_pipeline_id).is_none() {
-                return;
-            }
 
-            let (translated_point, translated_pipeline_id) =
-                webrender_api.translate_point_to_layer_space(&point.to_untyped());
-            let event_to_send = match mouse_window_event {
-                MouseWindowEvent::Click(button, _) => {
-                    MouseButtonEvent(MouseEventType::Click, button, translated_point)
-                }
-                MouseWindowEvent::MouseDown(button, _) => {
-                    MouseButtonEvent(MouseEventType::MouseDown, button, translated_point)
-                }
-                MouseWindowEvent::MouseUp(button, _) => {
-                    MouseButtonEvent(MouseEventType::MouseUp, button, translated_point)
-                }
-            };
-            let translated_pipeline_id = translated_pipeline_id.from_webrender();
-            let msg = ConstellationControlMsg::SendEvent(translated_pipeline_id, event_to_send);
-            if let Some(pipeline) = self.pipeline(translated_pipeline_id) {
+            if let Some(pipeline) = self.pipeline(root_pipeline_id) {
+                let dppx = self.page_zoom * self.device_pixels_per_screen_px();
+                let translated_point = (point / dppx).to_untyped();
+                let event_to_send = match mouse_window_event {
+                    MouseWindowEvent::Click(button, _) => {
+                        MouseButtonEvent(MouseEventType::Click, button, translated_point)
+                    }
+                    MouseWindowEvent::MouseDown(button, _) => {
+                        MouseButtonEvent(MouseEventType::MouseDown, button, translated_point)
+                    }
+                    MouseWindowEvent::MouseUp(button, _) => {
+                        MouseButtonEvent(MouseEventType::MouseUp, button, translated_point)
+                    }
+                };
+                let msg = ConstellationControlMsg::SendEvent(root_pipeline_id, event_to_send);
                 if let Err(e) = pipeline.script_chan.send(msg) {
                     warn!("Sending control event to script failed ({}).", e);
                 }
             }
             return
         }
 
         match self.find_topmost_layer_at_point(point / self.scene.scale) {
@@ -1426,31 +1422,29 @@ impl<Window: WindowMethods> IOCompositor
     }
 
     fn on_mouse_window_move_event_class(&mut self, cursor: TypedPoint2D<DevicePixel, f32>) {
         if opts::get().convert_mouse_to_touch {
             self.on_touch_move(TouchId(0), cursor);
             return
         }
 
-        if let Some(ref webrender_api) = self.webrender_api {
+        if self.webrender_api.is_some() {
             let root_pipeline_id = match self.get_root_pipeline_id() {
                 Some(root_pipeline_id) => root_pipeline_id,
                 None => return,
             };
             if self.pipeline(root_pipeline_id).is_none() {
                 return;
             }
 
-            let (translated_point, translated_pipeline_id) =
-                webrender_api.translate_point_to_layer_space(&cursor.to_untyped());
-            let translated_pipeline_id = translated_pipeline_id.from_webrender();
-            let event_to_send = MouseMoveEvent(Some(translated_point));
-            let msg = ConstellationControlMsg::SendEvent(translated_pipeline_id, event_to_send);
-            if let Some(pipeline) = self.pipeline(translated_pipeline_id) {
+            let dppx = self.page_zoom * self.device_pixels_per_screen_px();
+            let event_to_send = MouseMoveEvent(Some((cursor / dppx).to_untyped()));
+            let msg = ConstellationControlMsg::SendEvent(root_pipeline_id, event_to_send);
+            if let Some(pipeline) = self.pipeline(root_pipeline_id) {
                 if let Err(e) = pipeline.script_chan.send(msg) {
                     warn!("Sending mouse control event to script failed ({}).", e);
                 }
             }
             return
         }
 
         match self.find_topmost_layer_at_point(cursor / self.scene.scale) {